Lines Matching +full:iref +full:- +full:level

1 // SPDX-License-Identifier: GPL-2.0
15 #include <linux/backing-dev.h>
34 #include "disk-io.h"
42 #include "dev-replace.h"
46 #include "tree-log.h"
48 #include "space-info.h"
49 #include "block-group.h"
52 #include "extent-tree.h"
53 #include "root-tree.h"
55 #include "dir-item.h"
56 #include "uuid-tree.h"
63 /* If we have a 32-bit userspace and 64-bit kernel, then the UAPI
66 * the kernel about the 32-bit struct packing.
124 if (S_ISDIR(inode->i_mode)) in btrfs_mask_fsflags_for_type()
126 else if (S_ISREG(inode->i_mode)) in btrfs_mask_fsflags_for_type()
139 u32 flags = binode->flags; in btrfs_inode_flags_to_fsflags()
140 u32 ro_flags = binode->ro_flags; in btrfs_inode_flags_to_fsflags()
168 * Update inode->i_flags based on the btrfs internal flags.
175 if (binode->flags & BTRFS_INODE_SYNC) in btrfs_sync_inode_flags_to_i_flags()
177 if (binode->flags & BTRFS_INODE_IMMUTABLE) in btrfs_sync_inode_flags_to_i_flags()
179 if (binode->flags & BTRFS_INODE_APPEND) in btrfs_sync_inode_flags_to_i_flags()
181 if (binode->flags & BTRFS_INODE_NOATIME) in btrfs_sync_inode_flags_to_i_flags()
183 if (binode->flags & BTRFS_INODE_DIRSYNC) in btrfs_sync_inode_flags_to_i_flags()
185 if (binode->ro_flags & BTRFS_INODE_RO_VERITY) in btrfs_sync_inode_flags_to_i_flags()
188 set_mask_bits(&inode->i_flags, in btrfs_sync_inode_flags_to_i_flags()
204 return -EOPNOTSUPP; in check_fsflags()
208 return -EINVAL; in check_fsflags()
211 return -EINVAL; in check_fsflags()
215 return -EINVAL; in check_fsflags()
217 return -EINVAL; in check_fsflags()
226 return -EPERM; in check_fsflags_compatible()
233 if (memchr(vol_args->name, 0, sizeof(vol_args->name)) == NULL) in btrfs_check_ioctl_vol_args_path()
234 return -ENAMETOOLONG; in btrfs_check_ioctl_vol_args_path()
240 if (memchr(vol_args2->name, 0, sizeof(vol_args2->name)) == NULL) in btrfs_check_ioctl_vol_args2_subvol_name()
241 return -ENAMETOOLONG; in btrfs_check_ioctl_vol_args2_subvol_name()
263 struct btrfs_root *root = binode->root; in btrfs_fileattr_set()
271 return -EROFS; in btrfs_fileattr_set()
274 return -EOPNOTSUPP; in btrfs_fileattr_set()
276 fsflags = btrfs_mask_fsflags_for_type(inode, fa->flags); in btrfs_fileattr_set()
286 binode_flags = binode->flags; in btrfs_fileattr_set()
309 if (!fa->flags_valid) { in btrfs_fileattr_set()
322 if (S_ISREG(inode->i_mode)) { in btrfs_fileattr_set()
328 if (inode->i_size == 0) in btrfs_fileattr_set()
338 if (S_ISREG(inode->i_mode)) { in btrfs_fileattr_set()
339 if (inode->i_size == 0) in btrfs_fileattr_set()
358 return -ETXTBSY; in btrfs_fileattr_set()
363 comp = btrfs_compress_type2str(fs_info->compress_type); in btrfs_fileattr_set()
388 if (ret && ret != -ENODATA) { in btrfs_fileattr_set()
395 binode->flags = binode_flags; in btrfs_fileattr_set()
414 spin_lock(&fs_info->super_lock); in btrfs_exclop_start()
415 if (fs_info->exclusive_operation == BTRFS_EXCLOP_NONE) { in btrfs_exclop_start()
416 fs_info->exclusive_operation = type; in btrfs_exclop_start()
419 spin_unlock(&fs_info->super_lock); in btrfs_exclop_start()
430 * - the same type is already running
431 * - when trying to add a device and balance has been paused
432 * - not BTRFS_EXCLOP_NONE - this is intentionally incompatible and the caller
433 * must check the condition first that would allow none -> @type
438 spin_lock(&fs_info->super_lock); in btrfs_exclop_start_try_lock()
439 if (fs_info->exclusive_operation == type || in btrfs_exclop_start_try_lock()
440 (fs_info->exclusive_operation == BTRFS_EXCLOP_BALANCE_PAUSED && in btrfs_exclop_start_try_lock()
444 spin_unlock(&fs_info->super_lock); in btrfs_exclop_start_try_lock()
450 spin_unlock(&fs_info->super_lock); in btrfs_exclop_start_unlock()
455 spin_lock(&fs_info->super_lock); in btrfs_exclop_finish()
456 WRITE_ONCE(fs_info->exclusive_operation, BTRFS_EXCLOP_NONE); in btrfs_exclop_finish()
457 spin_unlock(&fs_info->super_lock); in btrfs_exclop_finish()
458 sysfs_notify(&fs_info->fs_devices->fsid_kobj, NULL, "exclusive_operation"); in btrfs_exclop_finish()
466 spin_lock(&fs_info->super_lock); in btrfs_exclop_balance()
467 ASSERT(fs_info->exclusive_operation == BTRFS_EXCLOP_BALANCE || in btrfs_exclop_balance()
468 fs_info->exclusive_operation == BTRFS_EXCLOP_DEV_ADD || in btrfs_exclop_balance()
469 fs_info->exclusive_operation == BTRFS_EXCLOP_NONE || in btrfs_exclop_balance()
470 fs_info->exclusive_operation == BTRFS_EXCLOP_BALANCE_PAUSED); in btrfs_exclop_balance()
471 fs_info->exclusive_operation = BTRFS_EXCLOP_BALANCE_PAUSED; in btrfs_exclop_balance()
472 spin_unlock(&fs_info->super_lock); in btrfs_exclop_balance()
475 spin_lock(&fs_info->super_lock); in btrfs_exclop_balance()
476 ASSERT(fs_info->exclusive_operation == BTRFS_EXCLOP_BALANCE_PAUSED); in btrfs_exclop_balance()
477 fs_info->exclusive_operation = BTRFS_EXCLOP_BALANCE; in btrfs_exclop_balance()
478 spin_unlock(&fs_info->super_lock); in btrfs_exclop_balance()
488 return put_user(inode->i_generation, arg); in btrfs_ioctl_getversion()
501 return -EPERM; in btrfs_ioctl_fitrim()
509 return -EOPNOTSUPP; in btrfs_ioctl_fitrim()
519 return -EROFS; in btrfs_ioctl_fitrim()
522 list_for_each_entry_rcu(device, &fs_info->fs_devices->devices, in btrfs_ioctl_fitrim()
524 if (!device->bdev || !bdev_max_discard_sectors(device->bdev)) in btrfs_ioctl_fitrim()
527 minlen = min_t(u64, bdev_discard_granularity(device->bdev), in btrfs_ioctl_fitrim()
533 return -EOPNOTSUPP; in btrfs_ioctl_fitrim()
535 return -EFAULT; in btrfs_ioctl_fitrim()
538 * NOTE: Don't truncate the range using super->total_bytes. Bytenr of in btrfs_ioctl_fitrim()
542 if (range.len < fs_info->sectorsize) in btrfs_ioctl_fitrim()
543 return -EINVAL; in btrfs_ioctl_fitrim()
549 return -EFAULT; in btrfs_ioctl_fitrim()
587 num_items += 2 * inherit->num_qgroups; in create_subvol_num_items()
602 struct btrfs_root *root = BTRFS_I(dir)->root; in create_subvol()
619 return -ENOMEM; in create_subvol()
621 ret = btrfs_get_free_objectid(fs_info->tree_root, &objectid); in create_subvol()
626 * Don't create subvolume whose level is not zero. Or qgroup will be in create_subvol()
627 * screwed up since it assumes subvolume qgroup's level to be 0. in create_subvol()
630 ret = -ENOSPC; in create_subvol()
640 ret = -ENOMEM; in create_subvol()
662 trans->block_rsv = &block_rsv; in create_subvol()
663 trans->bytes_reserved = block_rsv.size; in create_subvol()
678 inode_item = &root_item->inode; in create_subvol()
683 fs_info->nodesize); in create_subvol()
690 btrfs_set_root_bytenr(root_item, leaf->start); in create_subvol()
691 btrfs_set_root_generation(root_item, trans->transid); in create_subvol()
694 btrfs_set_root_used(root_item, leaf->len); in create_subvol()
699 generate_random_guid(root_item->uuid); in create_subvol()
700 btrfs_set_stack_timespec_sec(&root_item->otime, cur_time.tv_sec); in create_subvol()
701 btrfs_set_stack_timespec_nsec(&root_item->otime, cur_time.tv_nsec); in create_subvol()
702 root_item->ctime = root_item->otime; in create_subvol()
703 btrfs_set_root_ctransid(root_item, trans->transid); in create_subvol()
704 btrfs_set_root_otransid(root_item, trans->transid); in create_subvol()
713 ret = btrfs_insert_root(trans, fs_info->tree_root, &key, in create_subvol()
746 BTRFS_I(new_inode_args.inode)->root = new_root; in create_subvol()
755 ret = btrfs_uuid_tree_add(trans, root_item->uuid, in create_subvol()
774 trans->block_rsv = NULL; in create_subvol()
775 trans->bytes_reserved = 0; in create_subvol()
778 btrfs_block_rsv_release(fs_info, &block_rsv, (u64)-1, NULL); in create_subvol()
810 return -EOPNOTSUPP; in create_snapshot()
813 if (btrfs_root_refs(&root->root_item) == 0) in create_snapshot()
814 return -ENOENT; in create_snapshot()
816 if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) in create_snapshot()
817 return -EINVAL; in create_snapshot()
819 if (atomic_read(&root->nr_swapfiles)) { in create_snapshot()
822 return -ETXTBSY; in create_snapshot()
827 return -ENOMEM; in create_snapshot()
829 ret = get_anon_bdev(&pending_snapshot->anon_dev); in create_snapshot()
832 pending_snapshot->root_item = kzalloc(sizeof(struct btrfs_root_item), in create_snapshot()
834 pending_snapshot->path = btrfs_alloc_path(); in create_snapshot()
835 if (!pending_snapshot->root_item || !pending_snapshot->path) { in create_snapshot()
836 ret = -ENOMEM; in create_snapshot()
840 block_rsv = &pending_snapshot->block_rsv; in create_snapshot()
848 ret = btrfs_subvolume_reserve_metadata(BTRFS_I(dir)->root, block_rsv, in create_snapshot()
852 qgroup_reserved = block_rsv->qgroup_rsv_reserved; in create_snapshot()
854 pending_snapshot->dentry = dentry; in create_snapshot()
855 pending_snapshot->root = root; in create_snapshot()
856 pending_snapshot->readonly = readonly; in create_snapshot()
857 pending_snapshot->dir = BTRFS_I(dir); in create_snapshot()
858 pending_snapshot->inherit = inherit; in create_snapshot()
865 ret = btrfs_record_root_in_trans(trans, BTRFS_I(dir)->root); in create_snapshot()
873 trans->pending_snapshot = pending_snapshot; in create_snapshot()
879 ret = pending_snapshot->error; in create_snapshot()
883 ret = btrfs_orphan_cleanup(pending_snapshot->snap); in create_snapshot()
887 inode = btrfs_lookup_dentry(d_inode(dentry->d_parent), dentry); in create_snapshot()
895 pending_snapshot->anon_dev = 0; in create_snapshot()
898 if (ret && pending_snapshot->snap) in create_snapshot()
899 pending_snapshot->snap->anon_dev = 0; in create_snapshot()
900 btrfs_put_root(pending_snapshot->snap); in create_snapshot()
901 btrfs_block_rsv_release(fs_info, block_rsv, (u64)-1, NULL); in create_snapshot()
905 if (pending_snapshot->anon_dev) in create_snapshot()
906 free_anon_bdev(pending_snapshot->anon_dev); in create_snapshot()
907 kfree(pending_snapshot->root_item); in create_snapshot()
908 btrfs_free_path(pending_snapshot->path); in create_snapshot()
917 * 1. We can't do it if dir is read-only (done in permission())
919 * 3. We can't remove anything from append-only dir
925 * 6. If the victim is append-only or immutable we can't do anything with
927 * 7. If we were asked to remove a directory and victim isn't one - ENOTDIR.
928 * 8. If we were asked to remove a non-directory and victim isn't one - EISDIR.
940 return -ENOENT; in btrfs_may_delete()
943 if (d_inode(victim->d_parent) != dir) in btrfs_may_delete()
944 return -EINVAL; in btrfs_may_delete()
951 return -EPERM; in btrfs_may_delete()
955 return -EPERM; in btrfs_may_delete()
958 return -ENOTDIR; in btrfs_may_delete()
960 return -EBUSY; in btrfs_may_delete()
962 return -EISDIR; in btrfs_may_delete()
964 return -ENOENT; in btrfs_may_delete()
965 if (victim->d_flags & DCACHE_NFSFS_RENAMED) in btrfs_may_delete()
966 return -EBUSY; in btrfs_may_delete()
975 return -EEXIST; in btrfs_may_create()
977 return -ENOENT; in btrfs_may_create()
978 if (!fsuidgid_has_mapping(dir->i_sb, idmap)) in btrfs_may_create()
979 return -EOVERFLOW; in btrfs_may_create()
995 struct inode *dir = d_inode(parent->dentry); in btrfs_mksubvol()
1001 error = down_write_killable_nested(&dir->i_rwsem, I_MUTEX_PARENT); in btrfs_mksubvol()
1002 if (error == -EINTR) in btrfs_mksubvol()
1005 dentry = lookup_one(idmap, name, parent->dentry, namelen); in btrfs_mksubvol()
1018 error = btrfs_check_dir_item_collision(BTRFS_I(dir)->root, in btrfs_mksubvol()
1019 dir->i_ino, &name_str); in btrfs_mksubvol()
1023 down_read(&fs_info->subvol_sem); in btrfs_mksubvol()
1025 if (btrfs_root_refs(&BTRFS_I(dir)->root->root_item) == 0) in btrfs_mksubvol()
1036 up_read(&fs_info->subvol_sem); in btrfs_mksubvol()
1058 btrfs_drew_read_lock(&root->snapshot_lock); in btrfs_mksnapshot()
1069 atomic_inc(&root->snapshot_force_cow); in btrfs_mksnapshot()
1075 atomic_dec(&root->snapshot_force_cow); in btrfs_mksnapshot()
1077 btrfs_drew_read_unlock(&root->snapshot_lock); in btrfs_mksnapshot()
1085 * 0 - normal mode, newly claimed op started
1086 * >0 - normal mode, something else is running,
1088 * ECANCELED - cancel mode, successful cancel
1089 * ENOTCONN - cancel mode, operation not running anymore
1109 atomic_inc(&fs_info->reloc_cancel_req); in exclop_start_or_cancel_reloc()
1112 if (test_bit(BTRFS_FS_RELOC_RUNNING, &fs_info->flags)) in exclop_start_or_cancel_reloc()
1113 wait_on_bit(&fs_info->flags, BTRFS_FS_RELOC_RUNNING, in exclop_start_or_cancel_reloc()
1116 return -ECANCELED; in exclop_start_or_cancel_reloc()
1120 return -ENOTCONN; in exclop_start_or_cancel_reloc()
1132 struct btrfs_root *root = BTRFS_I(inode)->root; in btrfs_ioctl_resize()
1144 return -EPERM; in btrfs_ioctl_resize()
1163 sizestr = vol_args->name; in btrfs_ioctl_resize()
1174 devstr = vol_args->name; in btrfs_ioctl_resize()
1179 ret = -EINVAL; in btrfs_ioctl_resize()
1186 device = btrfs_find_device(fs_info->fs_devices, &args); in btrfs_ioctl_resize()
1190 ret = -ENODEV; in btrfs_ioctl_resize()
1194 if (!test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state)) { in btrfs_ioctl_resize()
1198 ret = -EPERM; in btrfs_ioctl_resize()
1203 new_size = bdev_nr_bytes(device->bdev); in btrfs_ioctl_resize()
1205 if (sizestr[0] == '-') { in btrfs_ioctl_resize()
1206 mod = -1; in btrfs_ioctl_resize()
1214 ret = -EINVAL; in btrfs_ioctl_resize()
1219 if (test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state)) { in btrfs_ioctl_resize()
1220 ret = -EPERM; in btrfs_ioctl_resize()
1228 ret = -EINVAL; in btrfs_ioctl_resize()
1231 new_size = old_size - new_size; in btrfs_ioctl_resize()
1233 if (new_size > ULLONG_MAX - old_size) { in btrfs_ioctl_resize()
1234 ret = -ERANGE; in btrfs_ioctl_resize()
1241 ret = -EINVAL; in btrfs_ioctl_resize()
1244 if (new_size > bdev_nr_bytes(device->bdev)) { in btrfs_ioctl_resize()
1245 ret = -EFBIG; in btrfs_ioctl_resize()
1249 new_size = round_down(new_size, fs_info->sectorsize); in btrfs_ioctl_resize()
1266 btrfs_dev_name(device), device->devid, in btrfs_ioctl_resize()
1286 if (!S_ISDIR(file_inode(file)->i_mode)) in __btrfs_ioctl_snap_create()
1287 return -ENOTDIR; in __btrfs_ioctl_snap_create()
1295 ret = -EINVAL; in __btrfs_ioctl_snap_create()
1301 ret = -EEXIST; in __btrfs_ioctl_snap_create()
1306 ret = btrfs_mksubvol(&file->f_path, idmap, name, in __btrfs_ioctl_snap_create()
1312 ret = -EINVAL; in __btrfs_ioctl_snap_create()
1317 if (src_inode->i_sb != file_inode(file)->i_sb) { in __btrfs_ioctl_snap_create()
1318 btrfs_info(BTRFS_I(file_inode(file))->root->fs_info, in __btrfs_ioctl_snap_create()
1320 ret = -EXDEV; in __btrfs_ioctl_snap_create()
1326 ret = -EPERM; in __btrfs_ioctl_snap_create()
1335 ret = -EINVAL; in __btrfs_ioctl_snap_create()
1337 ret = btrfs_mksnapshot(&file->f_path, idmap, in __btrfs_ioctl_snap_create()
1339 BTRFS_I(src_inode)->root, in __btrfs_ioctl_snap_create()
1355 if (!S_ISDIR(file_inode(file)->i_mode)) in btrfs_ioctl_snap_create()
1356 return -ENOTDIR; in btrfs_ioctl_snap_create()
1366 vol_args->name, vol_args->fd, subvol, in btrfs_ioctl_snap_create()
1382 if (!S_ISDIR(file_inode(file)->i_mode)) in btrfs_ioctl_snap_create_v2()
1383 return -ENOTDIR; in btrfs_ioctl_snap_create_v2()
1392 if (vol_args->flags & ~BTRFS_SUBVOL_CREATE_ARGS_MASK) { in btrfs_ioctl_snap_create_v2()
1393 ret = -EOPNOTSUPP; in btrfs_ioctl_snap_create_v2()
1397 if (vol_args->flags & BTRFS_SUBVOL_RDONLY) in btrfs_ioctl_snap_create_v2()
1399 if (vol_args->flags & BTRFS_SUBVOL_QGROUP_INHERIT) { in btrfs_ioctl_snap_create_v2()
1402 if (vol_args->size < sizeof(*inherit) || in btrfs_ioctl_snap_create_v2()
1403 vol_args->size > PAGE_SIZE) { in btrfs_ioctl_snap_create_v2()
1404 ret = -EINVAL; in btrfs_ioctl_snap_create_v2()
1407 inherit = memdup_user(vol_args->qgroup_inherit, vol_args->size); in btrfs_ioctl_snap_create_v2()
1413 ret = btrfs_qgroup_check_inherit(fs_info, inherit, vol_args->size); in btrfs_ioctl_snap_create_v2()
1419 vol_args->name, vol_args->fd, subvol, in btrfs_ioctl_snap_create_v2()
1434 struct btrfs_root *root = BTRFS_I(inode)->root; in btrfs_ioctl_subvol_getflags()
1439 return -EINVAL; in btrfs_ioctl_subvol_getflags()
1441 down_read(&fs_info->subvol_sem); in btrfs_ioctl_subvol_getflags()
1444 up_read(&fs_info->subvol_sem); in btrfs_ioctl_subvol_getflags()
1447 ret = -EFAULT; in btrfs_ioctl_subvol_getflags()
1457 struct btrfs_root *root = BTRFS_I(inode)->root; in btrfs_ioctl_subvol_setflags()
1464 return -EPERM; in btrfs_ioctl_subvol_setflags()
1471 ret = -EINVAL; in btrfs_ioctl_subvol_setflags()
1476 ret = -EFAULT; in btrfs_ioctl_subvol_setflags()
1481 ret = -EOPNOTSUPP; in btrfs_ioctl_subvol_setflags()
1485 down_write(&fs_info->subvol_sem); in btrfs_ioctl_subvol_setflags()
1491 root_flags = btrfs_root_flags(&root->root_item); in btrfs_ioctl_subvol_setflags()
1493 btrfs_set_root_flags(&root->root_item, in btrfs_ioctl_subvol_setflags()
1497 * Block RO -> RW transition if this subvolume is involved in in btrfs_ioctl_subvol_setflags()
1500 spin_lock(&root->root_item_lock); in btrfs_ioctl_subvol_setflags()
1501 if (root->send_in_progress == 0) { in btrfs_ioctl_subvol_setflags()
1502 btrfs_set_root_flags(&root->root_item, in btrfs_ioctl_subvol_setflags()
1504 spin_unlock(&root->root_item_lock); in btrfs_ioctl_subvol_setflags()
1506 spin_unlock(&root->root_item_lock); in btrfs_ioctl_subvol_setflags()
1508 "Attempt to set subvolume %llu read-write during send", in btrfs_ioctl_subvol_setflags()
1510 ret = -EPERM; in btrfs_ioctl_subvol_setflags()
1521 ret = btrfs_update_root(trans, fs_info->tree_root, in btrfs_ioctl_subvol_setflags()
1522 &root->root_key, &root->root_item); in btrfs_ioctl_subvol_setflags()
1532 btrfs_set_root_flags(&root->root_item, root_flags); in btrfs_ioctl_subvol_setflags()
1534 up_write(&fs_info->subvol_sem); in btrfs_ioctl_subvol_setflags()
1547 test.objectid = sk->min_objectid; in key_in_sk()
1548 test.type = sk->min_type; in key_in_sk()
1549 test.offset = sk->min_offset; in key_in_sk()
1555 test.objectid = sk->max_objectid; in key_in_sk()
1556 test.type = sk->max_type; in key_in_sk()
1557 test.offset = sk->max_offset; in key_in_sk()
1584 leaf = path->nodes[0]; in copy_to_sk()
1585 slot = path->slots[0]; in copy_to_sk()
1588 if (btrfs_header_generation(leaf) > sk->max_transid) { in copy_to_sk()
1610 * handle -EOVERFLOW in copy_to_sk()
1615 ret = -EOVERFLOW; in copy_to_sk()
1623 sh.objectid = key->objectid; in copy_to_sk()
1624 sh.offset = key->offset; in copy_to_sk()
1625 sh.type = key->type; in copy_to_sk()
1631 * can fault in the pages and -EFAULT there if there's a in copy_to_sk()
1651 *sk_offset -= sizeof(sh); in copy_to_sk()
1659 if (ret) /* -EOVERFLOW from above */ in copy_to_sk()
1662 if (*num_found >= sk->nr_items) { in copy_to_sk()
1669 test.objectid = sk->max_objectid; in copy_to_sk()
1670 test.type = sk->max_type; in copy_to_sk()
1671 test.offset = sk->max_offset; in copy_to_sk()
1674 else if (key->offset < (u64)-1) in copy_to_sk()
1675 key->offset++; in copy_to_sk()
1676 else if (key->type < (u8)-1) { in copy_to_sk()
1677 key->offset = 0; in copy_to_sk()
1678 key->type++; in copy_to_sk()
1679 } else if (key->objectid < (u64)-1) { in copy_to_sk()
1680 key->offset = 0; in copy_to_sk()
1681 key->type = 0; in copy_to_sk()
1682 key->objectid++; in copy_to_sk()
1692 * -EOVERFLOW: item was to large for buffer in copy_to_sk()
1693 * -EFAULT: could not copy extent buffer back to userspace in copy_to_sk()
1713 return -EOVERFLOW; in search_ioctl()
1718 return -ENOMEM; in search_ioctl()
1720 if (sk->tree_id == 0) { in search_ioctl()
1722 root = btrfs_grab_root(BTRFS_I(inode)->root); in search_ioctl()
1724 root = btrfs_get_fs_root(info, sk->tree_id, true); in search_ioctl()
1731 key.objectid = sk->min_objectid; in search_ioctl()
1732 key.type = sk->min_type; in search_ioctl()
1733 key.offset = sk->min_offset; in search_ioctl()
1736 ret = -EFAULT; in search_ioctl()
1738 * Ensure that the whole user buffer is faulted in at sub-page in search_ioctl()
1739 * granularity, otherwise the loop may live-lock. in search_ioctl()
1742 *buf_size - sk_offset)) in search_ioctl()
1745 ret = btrfs_search_forward(root, &key, path, sk->min_transid); in search_ioctl()
1761 sk->nr_items = num_found; in search_ioctl()
1776 return -EPERM; in btrfs_ioctl_tree_search()
1778 if (copy_from_user(&sk, &uargs->key, sizeof(sk))) in btrfs_ioctl_tree_search()
1779 return -EFAULT; in btrfs_ioctl_tree_search()
1781 buf_size = sizeof(uargs->buf); in btrfs_ioctl_tree_search()
1783 ret = search_ioctl(inode, &sk, &buf_size, uargs->buf); in btrfs_ioctl_tree_search()
1789 if (ret == -EOVERFLOW) in btrfs_ioctl_tree_search()
1792 if (ret == 0 && copy_to_user(&uargs->key, &sk, sizeof(sk))) in btrfs_ioctl_tree_search()
1793 ret = -EFAULT; in btrfs_ioctl_tree_search()
1807 return -EPERM; in btrfs_ioctl_tree_search_v2()
1811 return -EFAULT; in btrfs_ioctl_tree_search_v2()
1820 (char __user *)(&uarg->buf[0])); in btrfs_ioctl_tree_search_v2()
1821 if (ret == 0 && copy_to_user(&uarg->key, &args.key, sizeof(args.key))) in btrfs_ioctl_tree_search_v2()
1822 ret = -EFAULT; in btrfs_ioctl_tree_search_v2()
1823 else if (ret == -EOVERFLOW && in btrfs_ioctl_tree_search_v2()
1824 copy_to_user(&uarg->buf_size, &buf_size, sizeof(buf_size))) in btrfs_ioctl_tree_search_v2()
1825 ret = -EFAULT; in btrfs_ioctl_tree_search_v2()
1840 int ret = -1; in btrfs_search_path_in_tree()
1844 struct btrfs_inode_ref *iref; in btrfs_search_path_in_tree() local
1855 return -ENOMEM; in btrfs_search_path_in_tree()
1857 ptr = &name[BTRFS_INO_LOOKUP_PATH_MAX - 1]; in btrfs_search_path_in_tree()
1868 key.offset = (u64)-1; in btrfs_search_path_in_tree()
1875 ret = -ENOENT; in btrfs_search_path_in_tree()
1879 l = path->nodes[0]; in btrfs_search_path_in_tree()
1880 slot = path->slots[0]; in btrfs_search_path_in_tree()
1882 iref = btrfs_item_ptr(l, slot, struct btrfs_inode_ref); in btrfs_search_path_in_tree()
1883 len = btrfs_inode_ref_name_len(l, iref); in btrfs_search_path_in_tree()
1884 ptr -= len + 1; in btrfs_search_path_in_tree()
1887 ret = -ENAMETOOLONG; in btrfs_search_path_in_tree()
1892 read_extent_buffer(l, ptr, (unsigned long)(iref + 1), len); in btrfs_search_path_in_tree()
1899 key.offset = (u64)-1; in btrfs_search_path_in_tree()
1915 struct btrfs_fs_info *fs_info = BTRFS_I(inode)->root->fs_info; in btrfs_search_path_in_tree_user()
1917 u64 treeid = btrfs_root_id(BTRFS_I(inode)->root); in btrfs_search_path_in_tree_user()
1918 u64 dirid = args->dirid; in btrfs_search_path_in_tree_user()
1921 struct btrfs_inode_ref *iref; in btrfs_search_path_in_tree_user() local
1936 return -ENOMEM; in btrfs_search_path_in_tree_user()
1943 ptr = &args->path[BTRFS_INO_LOOKUP_USER_PATH_MAX - 1]; in btrfs_search_path_in_tree_user()
1953 key.offset = (u64)-1; in btrfs_search_path_in_tree_user()
1959 ret = -ENOENT; in btrfs_search_path_in_tree_user()
1963 leaf = path->nodes[0]; in btrfs_search_path_in_tree_user()
1964 slot = path->slots[0]; in btrfs_search_path_in_tree_user()
1966 iref = btrfs_item_ptr(leaf, slot, struct btrfs_inode_ref); in btrfs_search_path_in_tree_user()
1967 len = btrfs_inode_ref_name_len(leaf, iref); in btrfs_search_path_in_tree_user()
1968 ptr -= len + 1; in btrfs_search_path_in_tree_user()
1970 if (ptr < args->path) { in btrfs_search_path_in_tree_user()
1971 ret = -ENAMETOOLONG; in btrfs_search_path_in_tree_user()
1977 (unsigned long)(iref + 1), len); in btrfs_search_path_in_tree_user()
1985 ret = -ENOENT; in btrfs_search_path_in_tree_user()
1989 leaf = path->nodes[0]; in btrfs_search_path_in_tree_user()
1990 slot = path->slots[0]; in btrfs_search_path_in_tree_user()
1993 ret = -ENOENT; in btrfs_search_path_in_tree_user()
2013 ret = -EACCES; in btrfs_search_path_in_tree_user()
2020 ret = -EACCES; in btrfs_search_path_in_tree_user()
2025 key.offset = (u64)-1; in btrfs_search_path_in_tree_user()
2029 memmove(args->path, ptr, total_len); in btrfs_search_path_in_tree_user()
2030 args->path[total_len] = '\0'; in btrfs_search_path_in_tree_user()
2039 key.offset = args->treeid; in btrfs_search_path_in_tree_user()
2040 ret = btrfs_search_slot(NULL, fs_info->tree_root, &key, path, 0, 0); in btrfs_search_path_in_tree_user()
2044 ret = -ENOENT; in btrfs_search_path_in_tree_user()
2048 leaf = path->nodes[0]; in btrfs_search_path_in_tree_user()
2049 slot = path->slots[0]; in btrfs_search_path_in_tree_user()
2056 if (args->dirid != btrfs_root_ref_dirid(leaf, rref)) { in btrfs_search_path_in_tree_user()
2057 ret = -EINVAL; in btrfs_search_path_in_tree_user()
2063 item_len -= sizeof(struct btrfs_root_ref); in btrfs_search_path_in_tree_user()
2064 read_extent_buffer(leaf, args->name, item_off, item_len); in btrfs_search_path_in_tree_user()
2065 args->name[item_len] = 0; in btrfs_search_path_in_tree_user()
2088 if (args->treeid == 0) in btrfs_ioctl_ino_lookup()
2089 args->treeid = btrfs_root_id(root); in btrfs_ioctl_ino_lookup()
2091 if (args->objectid == BTRFS_FIRST_FREE_OBJECTID) { in btrfs_ioctl_ino_lookup()
2092 args->name[0] = 0; in btrfs_ioctl_ino_lookup()
2097 ret = -EPERM; in btrfs_ioctl_ino_lookup()
2101 ret = btrfs_search_path_in_tree(root->fs_info, in btrfs_ioctl_ino_lookup()
2102 args->treeid, args->objectid, in btrfs_ioctl_ino_lookup()
2103 args->name); in btrfs_ioctl_ino_lookup()
2107 ret = -EFAULT; in btrfs_ioctl_ino_lookup()
2119 * path construction. -EACCES will be returned in case of failure.
2122 * exist under fd's inode, -EACCES will be returned.
2137 if (args->dirid == BTRFS_FIRST_FREE_OBJECTID && in btrfs_ioctl_ino_lookup_user()
2144 return -EACCES; in btrfs_ioctl_ino_lookup_user()
2150 ret = -EFAULT; in btrfs_ioctl_ino_lookup_user()
2174 return -ENOMEM; in btrfs_ioctl_get_subvol_info()
2179 return -ENOMEM; in btrfs_ioctl_get_subvol_info()
2182 fs_info = BTRFS_I(inode)->root->fs_info; in btrfs_ioctl_get_subvol_info()
2185 key.objectid = btrfs_root_id(BTRFS_I(inode)->root); in btrfs_ioctl_get_subvol_info()
2191 root_item = &root->root_item; in btrfs_ioctl_get_subvol_info()
2193 subvol_info->treeid = key.objectid; in btrfs_ioctl_get_subvol_info()
2195 subvol_info->generation = btrfs_root_generation(root_item); in btrfs_ioctl_get_subvol_info()
2196 subvol_info->flags = btrfs_root_flags(root_item); in btrfs_ioctl_get_subvol_info()
2198 memcpy(subvol_info->uuid, root_item->uuid, BTRFS_UUID_SIZE); in btrfs_ioctl_get_subvol_info()
2199 memcpy(subvol_info->parent_uuid, root_item->parent_uuid, in btrfs_ioctl_get_subvol_info()
2201 memcpy(subvol_info->received_uuid, root_item->received_uuid, in btrfs_ioctl_get_subvol_info()
2204 subvol_info->ctransid = btrfs_root_ctransid(root_item); in btrfs_ioctl_get_subvol_info()
2205 subvol_info->ctime.sec = btrfs_stack_timespec_sec(&root_item->ctime); in btrfs_ioctl_get_subvol_info()
2206 subvol_info->ctime.nsec = btrfs_stack_timespec_nsec(&root_item->ctime); in btrfs_ioctl_get_subvol_info()
2208 subvol_info->otransid = btrfs_root_otransid(root_item); in btrfs_ioctl_get_subvol_info()
2209 subvol_info->otime.sec = btrfs_stack_timespec_sec(&root_item->otime); in btrfs_ioctl_get_subvol_info()
2210 subvol_info->otime.nsec = btrfs_stack_timespec_nsec(&root_item->otime); in btrfs_ioctl_get_subvol_info()
2212 subvol_info->stransid = btrfs_root_stransid(root_item); in btrfs_ioctl_get_subvol_info()
2213 subvol_info->stime.sec = btrfs_stack_timespec_sec(&root_item->stime); in btrfs_ioctl_get_subvol_info()
2214 subvol_info->stime.nsec = btrfs_stack_timespec_nsec(&root_item->stime); in btrfs_ioctl_get_subvol_info()
2216 subvol_info->rtransid = btrfs_root_rtransid(root_item); in btrfs_ioctl_get_subvol_info()
2217 subvol_info->rtime.sec = btrfs_stack_timespec_sec(&root_item->rtime); in btrfs_ioctl_get_subvol_info()
2218 subvol_info->rtime.nsec = btrfs_stack_timespec_nsec(&root_item->rtime); in btrfs_ioctl_get_subvol_info()
2224 ret = btrfs_search_slot(NULL, fs_info->tree_root, &key, path, 0, 0); in btrfs_ioctl_get_subvol_info()
2227 } else if (path->slots[0] >= in btrfs_ioctl_get_subvol_info()
2228 btrfs_header_nritems(path->nodes[0])) { in btrfs_ioctl_get_subvol_info()
2229 ret = btrfs_next_leaf(fs_info->tree_root, path); in btrfs_ioctl_get_subvol_info()
2233 ret = -EUCLEAN; in btrfs_ioctl_get_subvol_info()
2238 leaf = path->nodes[0]; in btrfs_ioctl_get_subvol_info()
2239 slot = path->slots[0]; in btrfs_ioctl_get_subvol_info()
2241 if (key.objectid == subvol_info->treeid && in btrfs_ioctl_get_subvol_info()
2243 subvol_info->parent_id = key.offset; in btrfs_ioctl_get_subvol_info()
2246 subvol_info->dirid = btrfs_root_ref_dirid(leaf, rref); in btrfs_ioctl_get_subvol_info()
2251 - sizeof(struct btrfs_root_ref); in btrfs_ioctl_get_subvol_info()
2252 read_extent_buffer(leaf, subvol_info->name, in btrfs_ioctl_get_subvol_info()
2255 ret = -ENOENT; in btrfs_ioctl_get_subvol_info()
2263 ret = -EFAULT; in btrfs_ioctl_get_subvol_info()
2292 return -ENOMEM; in btrfs_ioctl_get_subvol_rootref()
2303 key.offset = rootrefs->min_treeid; in btrfs_ioctl_get_subvol_rootref()
2306 root = root->fs_info->tree_root; in btrfs_ioctl_get_subvol_rootref()
2310 } else if (path->slots[0] >= in btrfs_ioctl_get_subvol_rootref()
2311 btrfs_header_nritems(path->nodes[0])) { in btrfs_ioctl_get_subvol_rootref()
2316 ret = -EUCLEAN; in btrfs_ioctl_get_subvol_rootref()
2321 leaf = path->nodes[0]; in btrfs_ioctl_get_subvol_rootref()
2322 slot = path->slots[0]; in btrfs_ioctl_get_subvol_rootref()
2331 ret = -EOVERFLOW; in btrfs_ioctl_get_subvol_rootref()
2336 rootrefs->rootref[found].treeid = key.offset; in btrfs_ioctl_get_subvol_rootref()
2337 rootrefs->rootref[found].dirid = in btrfs_ioctl_get_subvol_rootref()
2345 ret = -EUCLEAN; in btrfs_ioctl_get_subvol_rootref()
2353 if (!ret || ret == -EOVERFLOW) { in btrfs_ioctl_get_subvol_rootref()
2354 rootrefs->num_items = found; in btrfs_ioctl_get_subvol_rootref()
2357 rootrefs->min_treeid = in btrfs_ioctl_get_subvol_rootref()
2358 rootrefs->rootref[found - 1].treeid + 1; in btrfs_ioctl_get_subvol_rootref()
2360 ret = -EFAULT; in btrfs_ioctl_get_subvol_rootref()
2372 struct dentry *parent = file->f_path.dentry; in btrfs_ioctl_snap_destroy()
2377 struct btrfs_root *root = BTRFS_I(dir)->root; in btrfs_ioctl_snap_destroy()
2391 return -EOPNOTSUPP; in btrfs_ioctl_snap_destroy()
2399 if (vol_args2->flags & ~BTRFS_SUBVOL_DELETE_ARGS_MASK) { in btrfs_ioctl_snap_destroy()
2400 ret = -EOPNOTSUPP; in btrfs_ioctl_snap_destroy()
2408 if (!(vol_args2->flags & BTRFS_SUBVOL_SPEC_BY_ID)) { in btrfs_ioctl_snap_destroy()
2412 subvol_name = vol_args2->name; in btrfs_ioctl_snap_destroy()
2420 if (vol_args2->subvolid < BTRFS_FIRST_FREE_OBJECTID) { in btrfs_ioctl_snap_destroy()
2421 ret = -EINVAL; in btrfs_ioctl_snap_destroy()
2429 dentry = btrfs_get_dentry(fs_info->sb, in btrfs_ioctl_snap_destroy()
2431 vol_args2->subvolid, 0); in btrfs_ioctl_snap_destroy()
2444 * At this point dentry->d_name can point to '/' if the in btrfs_ioctl_snap_destroy()
2448 * one with ->d_name pointing to the in btrfs_ioctl_snap_destroy()
2477 ret = -EOPNOTSUPP; in btrfs_ioctl_snap_destroy()
2482 fs_info, vol_args2->subvolid); in btrfs_ioctl_snap_destroy()
2499 subvol_name = vol_args->name; in btrfs_ioctl_snap_destroy()
2510 ret = -EINVAL; in btrfs_ioctl_snap_destroy()
2514 if (!S_ISDIR(dir->i_mode)) { in btrfs_ioctl_snap_destroy()
2515 ret = -ENOTDIR; in btrfs_ioctl_snap_destroy()
2519 ret = down_write_killable_nested(&dir->i_rwsem, I_MUTEX_PARENT); in btrfs_ioctl_snap_destroy()
2520 if (ret == -EINTR) in btrfs_ioctl_snap_destroy()
2529 ret = -ENOENT; in btrfs_ioctl_snap_destroy()
2534 dest = BTRFS_I(inode)->root; in btrfs_ioctl_snap_destroy()
2549 ret = -EPERM; in btrfs_ioctl_snap_destroy()
2560 ret = -EINVAL; in btrfs_ioctl_snap_destroy()
2575 ret = -EINVAL; in btrfs_ioctl_snap_destroy()
2605 struct btrfs_root *root = BTRFS_I(inode)->root; in btrfs_ioctl_defrag()
2614 ret = -EROFS; in btrfs_ioctl_defrag()
2618 switch (inode->i_mode & S_IFMT) { in btrfs_ioctl_defrag()
2621 ret = -EPERM; in btrfs_ioctl_defrag()
2630 * running and allows defrag on files open in read-only mode. in btrfs_ioctl_defrag()
2634 ret = -EPERM; in btrfs_ioctl_defrag()
2640 ret = -EFAULT; in btrfs_ioctl_defrag()
2644 ret = -EOPNOTSUPP; in btrfs_ioctl_defrag()
2650 range.extent_thresh = (u32)-1; in btrfs_ioctl_defrag()
2654 range.len = (u64)-1; in btrfs_ioctl_defrag()
2656 ret = btrfs_defrag_file(file_inode(file), &file->f_ra, in btrfs_ioctl_defrag()
2662 ret = -EINVAL; in btrfs_ioctl_defrag()
2676 return -EPERM; in btrfs_ioctl_add_dev()
2680 return -EINVAL; in btrfs_ioctl_add_dev()
2683 if (fs_info->fs_devices->temp_fsid) { in btrfs_ioctl_add_dev()
2685 "device add not supported on cloned temp-fsid mount"); in btrfs_ioctl_add_dev()
2686 return -EINVAL; in btrfs_ioctl_add_dev()
2698 fs_info->exclusive_operation = BTRFS_EXCLOP_DEV_ADD; in btrfs_ioctl_add_dev()
2713 ret = btrfs_init_new_device(fs_info, vol_args->name); in btrfs_ioctl_add_dev()
2716 btrfs_info(fs_info, "disk added %s", vol_args->name); in btrfs_ioctl_add_dev()
2739 return -EPERM; in btrfs_ioctl_rm_dev_v2()
2745 if (vol_args->flags & ~BTRFS_DEVICE_REMOVE_ARGS_MASK) { in btrfs_ioctl_rm_dev_v2()
2746 ret = -EOPNOTSUPP; in btrfs_ioctl_rm_dev_v2()
2754 if (vol_args->flags & BTRFS_DEVICE_SPEC_BY_ID) { in btrfs_ioctl_rm_dev_v2()
2755 args.devid = vol_args->devid; in btrfs_ioctl_rm_dev_v2()
2756 } else if (!strcmp("cancel", vol_args->name)) { in btrfs_ioctl_rm_dev_v2()
2759 ret = btrfs_get_dev_args_from_path(fs_info, &args, vol_args->name); in btrfs_ioctl_rm_dev_v2()
2779 if (vol_args->flags & BTRFS_DEVICE_SPEC_BY_ID) in btrfs_ioctl_rm_dev_v2()
2781 vol_args->devid); in btrfs_ioctl_rm_dev_v2()
2784 vol_args->name); in btrfs_ioctl_rm_dev_v2()
2807 return -EPERM; in btrfs_ioctl_rm_dev()
2817 if (!strcmp("cancel", vol_args->name)) { in btrfs_ioctl_rm_dev()
2820 ret = btrfs_get_dev_args_from_path(fs_info, &args, vol_args->name); in btrfs_ioctl_rm_dev()
2834 btrfs_info(fs_info, "disk deleted %s", vol_args->name); in btrfs_ioctl_rm_dev()
2853 struct btrfs_fs_devices *fs_devices = fs_info->fs_devices; in btrfs_ioctl_fs_info()
2861 flags_in = fi_args->flags; in btrfs_ioctl_fs_info()
2865 fi_args->num_devices = fs_devices->num_devices; in btrfs_ioctl_fs_info()
2867 list_for_each_entry_rcu(device, &fs_devices->devices, dev_list) { in btrfs_ioctl_fs_info()
2868 if (device->devid > fi_args->max_id) in btrfs_ioctl_fs_info()
2869 fi_args->max_id = device->devid; in btrfs_ioctl_fs_info()
2873 memcpy(&fi_args->fsid, fs_devices->fsid, sizeof(fi_args->fsid)); in btrfs_ioctl_fs_info()
2874 fi_args->nodesize = fs_info->nodesize; in btrfs_ioctl_fs_info()
2875 fi_args->sectorsize = fs_info->sectorsize; in btrfs_ioctl_fs_info()
2876 fi_args->clone_alignment = fs_info->sectorsize; in btrfs_ioctl_fs_info()
2879 fi_args->csum_type = btrfs_super_csum_type(fs_info->super_copy); in btrfs_ioctl_fs_info()
2880 fi_args->csum_size = btrfs_super_csum_size(fs_info->super_copy); in btrfs_ioctl_fs_info()
2881 fi_args->flags |= BTRFS_FS_INFO_FLAG_CSUM_INFO; in btrfs_ioctl_fs_info()
2885 fi_args->generation = btrfs_get_fs_generation(fs_info); in btrfs_ioctl_fs_info()
2886 fi_args->flags |= BTRFS_FS_INFO_FLAG_GENERATION; in btrfs_ioctl_fs_info()
2890 memcpy(&fi_args->metadata_uuid, fs_devices->metadata_uuid, in btrfs_ioctl_fs_info()
2891 sizeof(fi_args->metadata_uuid)); in btrfs_ioctl_fs_info()
2892 fi_args->flags |= BTRFS_FS_INFO_FLAG_METADATA_UUID; in btrfs_ioctl_fs_info()
2896 ret = -EFAULT; in btrfs_ioctl_fs_info()
2914 args.devid = di_args->devid; in btrfs_ioctl_dev_info()
2915 if (!btrfs_is_empty_uuid(di_args->uuid)) in btrfs_ioctl_dev_info()
2916 args.uuid = di_args->uuid; in btrfs_ioctl_dev_info()
2919 dev = btrfs_find_device(fs_info->fs_devices, &args); in btrfs_ioctl_dev_info()
2921 ret = -ENODEV; in btrfs_ioctl_dev_info()
2925 di_args->devid = dev->devid; in btrfs_ioctl_dev_info()
2926 di_args->bytes_used = btrfs_device_get_bytes_used(dev); in btrfs_ioctl_dev_info()
2927 di_args->total_bytes = btrfs_device_get_total_bytes(dev); in btrfs_ioctl_dev_info()
2928 memcpy(di_args->uuid, dev->uuid, sizeof(di_args->uuid)); in btrfs_ioctl_dev_info()
2929 memcpy(di_args->fsid, dev->fs_devices->fsid, BTRFS_UUID_SIZE); in btrfs_ioctl_dev_info()
2930 if (dev->name) in btrfs_ioctl_dev_info()
2931 strscpy(di_args->path, btrfs_dev_name(dev), sizeof(di_args->path)); in btrfs_ioctl_dev_info()
2933 di_args->path[0] = '\0'; in btrfs_ioctl_dev_info()
2938 ret = -EFAULT; in btrfs_ioctl_dev_info()
2948 struct btrfs_root *root = BTRFS_I(inode)->root; in btrfs_ioctl_default_subvol()
2960 return -EPERM; in btrfs_ioctl_default_subvol()
2967 ret = -EFAULT; in btrfs_ioctl_default_subvol()
2980 ret = -ENOENT; in btrfs_ioctl_default_subvol()
2986 ret = -ENOMEM; in btrfs_ioctl_default_subvol()
2996 dir_id = btrfs_super_root_dir(fs_info->super_copy); in btrfs_ioctl_default_subvol()
2997 di = btrfs_lookup_dir_item(trans, fs_info->tree_root, path, in btrfs_ioctl_default_subvol()
3004 ret = -ENOENT; in btrfs_ioctl_default_subvol()
3008 btrfs_cpu_key_to_disk(&disk_key, &new_root->root_key); in btrfs_ioctl_default_subvol()
3009 btrfs_set_dir_item_key(path->nodes[0], di, &disk_key); in btrfs_ioctl_default_subvol()
3010 btrfs_mark_buffer_dirty(trans, path->nodes[0]); in btrfs_ioctl_default_subvol()
3028 space->total_bytes = 0; in get_block_group_info()
3029 space->used_bytes = 0; in get_block_group_info()
3030 space->flags = 0; in get_block_group_info()
3032 space->flags = block_group->flags; in get_block_group_info()
3033 space->total_bytes += block_group->length; in get_block_group_info()
3034 space->used_bytes += block_group->used; in get_block_group_info()
3062 return -EFAULT; in btrfs_ioctl_space_info()
3068 list_for_each_entry(tmp, &fs_info->space_info, list) { in btrfs_ioctl_space_info()
3069 if (tmp->flags == types[i]) { in btrfs_ioctl_space_info()
3078 down_read(&info->groups_sem); in btrfs_ioctl_space_info()
3080 if (!list_empty(&info->block_groups[c])) in btrfs_ioctl_space_info()
3083 up_read(&info->groups_sem); in btrfs_ioctl_space_info()
3102 * level. So, a whole page should be more than enough for everyone in btrfs_ioctl_space_info()
3105 return -ENOMEM; in btrfs_ioctl_space_info()
3110 return -ENOMEM; in btrfs_ioctl_space_info()
3121 list_for_each_entry(tmp, &fs_info->space_info, list) { in btrfs_ioctl_space_info()
3122 if (tmp->flags == types[i]) { in btrfs_ioctl_space_info()
3130 down_read(&info->groups_sem); in btrfs_ioctl_space_info()
3132 if (!list_empty(&info->block_groups[c])) { in btrfs_ioctl_space_info()
3133 get_block_group_info(&info->block_groups[c], in btrfs_ioctl_space_info()
3138 slot_count--; in btrfs_ioctl_space_info()
3143 up_read(&info->groups_sem); in btrfs_ioctl_space_info()
3150 struct btrfs_block_rsv *block_rsv = &fs_info->global_block_rsv; in btrfs_ioctl_space_info()
3152 spin_lock(&block_rsv->lock); in btrfs_ioctl_space_info()
3153 space.total_bytes = block_rsv->size; in btrfs_ioctl_space_info()
3154 space.used_bytes = block_rsv->size - block_rsv->reserved; in btrfs_ioctl_space_info()
3155 spin_unlock(&block_rsv->lock); in btrfs_ioctl_space_info()
3165 ret = -EFAULT; in btrfs_ioctl_space_info()
3170 ret = -EFAULT; in btrfs_ioctl_space_info()
3190 if (PTR_ERR(trans) != -ENOENT) in btrfs_ioctl_start_sync()
3194 transid = btrfs_get_last_trans_committed(root->fs_info); in btrfs_ioctl_start_sync()
3197 transid = trans->transid; in btrfs_ioctl_start_sync()
3202 return -EFAULT; in btrfs_ioctl_start_sync()
3214 return -EFAULT; in btrfs_ioctl_wait_sync()
3226 return -EPERM; in btrfs_ioctl_scrub()
3230 return -EINVAL; in btrfs_ioctl_scrub()
3237 if (sa->flags & ~BTRFS_SCRUB_SUPPORTED_FLAGS) { in btrfs_ioctl_scrub()
3238 ret = -EOPNOTSUPP; in btrfs_ioctl_scrub()
3242 if (!(sa->flags & BTRFS_SCRUB_READONLY)) { in btrfs_ioctl_scrub()
3248 ret = btrfs_scrub_dev(fs_info, sa->devid, sa->start, sa->end, in btrfs_ioctl_scrub()
3249 &sa->progress, sa->flags & BTRFS_SCRUB_READONLY, in btrfs_ioctl_scrub()
3256 * -ECANCELED from btrfs_scrub_dev() and return that error back to user in btrfs_ioctl_scrub()
3259 * previously (btrfs-progs does this). in btrfs_ioctl_scrub()
3261 * then return -EFAULT to signal the structure was not copied or it may in btrfs_ioctl_scrub()
3265 ret = -EFAULT; in btrfs_ioctl_scrub()
3267 if (!(sa->flags & BTRFS_SCRUB_READONLY)) in btrfs_ioctl_scrub()
3277 return -EPERM; in btrfs_ioctl_scrub_cancel()
3289 return -EPERM; in btrfs_ioctl_scrub_progress()
3295 ret = btrfs_scrub_progress(fs_info, sa->devid, &sa->progress); in btrfs_ioctl_scrub_progress()
3298 ret = -EFAULT; in btrfs_ioctl_scrub_progress()
3314 if ((sa->flags & BTRFS_DEV_STATS_RESET) && !capable(CAP_SYS_ADMIN)) { in btrfs_ioctl_get_dev_stats()
3316 return -EPERM; in btrfs_ioctl_get_dev_stats()
3322 ret = -EFAULT; in btrfs_ioctl_get_dev_stats()
3335 return -EPERM; in btrfs_ioctl_dev_replace()
3339 return -EINVAL; in btrfs_ioctl_dev_replace()
3346 switch (p->cmd) { in btrfs_ioctl_dev_replace()
3348 if (sb_rdonly(fs_info->sb)) { in btrfs_ioctl_dev_replace()
3349 ret = -EROFS; in btrfs_ioctl_dev_replace()
3364 p->result = btrfs_dev_replace_cancel(fs_info); in btrfs_ioctl_dev_replace()
3368 ret = -EINVAL; in btrfs_ioctl_dev_replace()
3372 if ((ret == 0 || ret == -ECANCELED) && copy_to_user(arg, p, sizeof(*p))) in btrfs_ioctl_dev_replace()
3373 ret = -EFAULT; in btrfs_ioctl_dev_replace()
3390 return -EPERM; in btrfs_ioctl_ino_to_path()
3394 ret = -ENOMEM; in btrfs_ioctl_ino_to_path()
3405 size = min_t(u32, ipa->size, 4096); in btrfs_ioctl_ino_to_path()
3413 ret = paths_from_inode(ipa->inum, ipath); in btrfs_ioctl_ino_to_path()
3417 for (i = 0; i < ipath->fspath->elem_cnt; ++i) { in btrfs_ioctl_ino_to_path()
3418 rel_ptr = ipath->fspath->val[i] - in btrfs_ioctl_ino_to_path()
3419 (u64)(unsigned long)ipath->fspath->val; in btrfs_ioctl_ino_to_path()
3420 ipath->fspath->val[i] = rel_ptr; in btrfs_ioctl_ino_to_path()
3425 ret = copy_to_user((void __user *)(unsigned long)ipa->fspath, in btrfs_ioctl_ino_to_path()
3426 ipath->fspath, size); in btrfs_ioctl_ino_to_path()
3428 ret = -EFAULT; in btrfs_ioctl_ino_to_path()
3451 return -EPERM; in btrfs_ioctl_logical_to_ino()
3459 size = min_t(u32, loi->size, SZ_64K); in btrfs_ioctl_logical_to_ino()
3462 if (memchr_inv(loi->reserved, 0, sizeof(loi->reserved))) { in btrfs_ioctl_logical_to_ino()
3463 ret = -EINVAL; in btrfs_ioctl_logical_to_ino()
3467 if (loi->flags & ~(BTRFS_LOGICAL_INO_ARGS_IGNORE_OFFSET)) { in btrfs_ioctl_logical_to_ino()
3468 ret = -EINVAL; in btrfs_ioctl_logical_to_ino()
3471 ignore_offset = loi->flags & BTRFS_LOGICAL_INO_ARGS_IGNORE_OFFSET; in btrfs_ioctl_logical_to_ino()
3472 size = min_t(u32, loi->size, SZ_16M); in btrfs_ioctl_logical_to_ino()
3483 ret = -ENOMEM; in btrfs_ioctl_logical_to_ino()
3486 ret = iterate_inodes_from_logical(loi->logical, fs_info, path, in btrfs_ioctl_logical_to_ino()
3489 if (ret == -EINVAL) in btrfs_ioctl_logical_to_ino()
3490 ret = -ENOENT; in btrfs_ioctl_logical_to_ino()
3494 ret = copy_to_user((void __user *)(unsigned long)loi->inodes, inodes, in btrfs_ioctl_logical_to_ino()
3497 ret = -EFAULT; in btrfs_ioctl_logical_to_ino()
3510 struct btrfs_balance_control *bctl = fs_info->balance_ctl; in btrfs_update_ioctl_balance_args()
3512 bargs->flags = bctl->flags; in btrfs_update_ioctl_balance_args()
3514 if (test_bit(BTRFS_FS_BALANCE_RUNNING, &fs_info->flags)) in btrfs_update_ioctl_balance_args()
3515 bargs->state |= BTRFS_BALANCE_STATE_RUNNING; in btrfs_update_ioctl_balance_args()
3516 if (atomic_read(&fs_info->balance_pause_req)) in btrfs_update_ioctl_balance_args()
3517 bargs->state |= BTRFS_BALANCE_STATE_PAUSE_REQ; in btrfs_update_ioctl_balance_args()
3518 if (atomic_read(&fs_info->balance_cancel_req)) in btrfs_update_ioctl_balance_args()
3519 bargs->state |= BTRFS_BALANCE_STATE_CANCEL_REQ; in btrfs_update_ioctl_balance_args()
3521 memcpy(&bargs->data, &bctl->data, sizeof(bargs->data)); in btrfs_update_ioctl_balance_args()
3522 memcpy(&bargs->meta, &bctl->meta, sizeof(bargs->meta)); in btrfs_update_ioctl_balance_args()
3523 memcpy(&bargs->sys, &bctl->sys, sizeof(bargs->sys)); in btrfs_update_ioctl_balance_args()
3525 spin_lock(&fs_info->balance_lock); in btrfs_update_ioctl_balance_args()
3526 memcpy(&bargs->stat, &bctl->stat, sizeof(bargs->stat)); in btrfs_update_ioctl_balance_args()
3527 spin_unlock(&fs_info->balance_lock); in btrfs_update_ioctl_balance_args()
3549 * (3) balance is paused -- special case (think resume) in btrfs_try_lock_balance()
3554 mutex_lock(&fs_info->balance_mutex); in btrfs_try_lock_balance()
3558 mutex_lock(&fs_info->balance_mutex); in btrfs_try_lock_balance()
3559 if (fs_info->balance_ctl) { in btrfs_try_lock_balance()
3561 if (test_bit(BTRFS_FS_BALANCE_RUNNING, &fs_info->flags)) { in btrfs_try_lock_balance()
3563 ret = -EINPROGRESS; in btrfs_try_lock_balance()
3567 mutex_unlock(&fs_info->balance_mutex); in btrfs_try_lock_balance()
3572 mutex_lock(&fs_info->balance_mutex); in btrfs_try_lock_balance()
3574 if (fs_info->balance_ctl && in btrfs_try_lock_balance()
3575 !test_bit(BTRFS_FS_BALANCE_RUNNING, &fs_info->flags)) { in btrfs_try_lock_balance()
3587 mutex_unlock(&fs_info->balance_mutex); in btrfs_try_lock_balance()
3591 mutex_unlock(&fs_info->balance_mutex); in btrfs_try_lock_balance()
3598 struct btrfs_root *root = BTRFS_I(file_inode(file))->root; in btrfs_ioctl_balance()
3599 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_ioctl_balance()
3606 return -EPERM; in btrfs_ioctl_balance()
3623 lockdep_assert_held(&fs_info->balance_mutex); in btrfs_ioctl_balance()
3625 if (bargs->flags & BTRFS_BALANCE_RESUME) { in btrfs_ioctl_balance()
3626 if (!fs_info->balance_ctl) { in btrfs_ioctl_balance()
3627 ret = -ENOTCONN; in btrfs_ioctl_balance()
3631 bctl = fs_info->balance_ctl; in btrfs_ioctl_balance()
3632 spin_lock(&fs_info->balance_lock); in btrfs_ioctl_balance()
3633 bctl->flags |= BTRFS_BALANCE_RESUME; in btrfs_ioctl_balance()
3634 spin_unlock(&fs_info->balance_lock); in btrfs_ioctl_balance()
3640 if (bargs->flags & ~(BTRFS_BALANCE_ARGS_MASK | BTRFS_BALANCE_TYPE_MASK)) { in btrfs_ioctl_balance()
3641 ret = -EINVAL; in btrfs_ioctl_balance()
3645 if (fs_info->balance_ctl) { in btrfs_ioctl_balance()
3646 ret = -EINPROGRESS; in btrfs_ioctl_balance()
3652 ret = -ENOMEM; in btrfs_ioctl_balance()
3656 memcpy(&bctl->data, &bargs->data, sizeof(bctl->data)); in btrfs_ioctl_balance()
3657 memcpy(&bctl->meta, &bargs->meta, sizeof(bctl->meta)); in btrfs_ioctl_balance()
3658 memcpy(&bctl->sys, &bargs->sys, sizeof(bctl->sys)); in btrfs_ioctl_balance()
3660 bctl->flags = bargs->flags; in btrfs_ioctl_balance()
3673 if (ret == 0 || ret == -ECANCELED) { in btrfs_ioctl_balance()
3675 ret = -EFAULT; in btrfs_ioctl_balance()
3680 mutex_unlock(&fs_info->balance_mutex); in btrfs_ioctl_balance()
3692 return -EPERM; in btrfs_ioctl_balance_ctl()
3701 return -EINVAL; in btrfs_ioctl_balance_ctl()
3711 return -EPERM; in btrfs_ioctl_balance_progress()
3713 mutex_lock(&fs_info->balance_mutex); in btrfs_ioctl_balance_progress()
3714 if (!fs_info->balance_ctl) { in btrfs_ioctl_balance_progress()
3715 ret = -ENOTCONN; in btrfs_ioctl_balance_progress()
3721 ret = -ENOMEM; in btrfs_ioctl_balance_progress()
3728 ret = -EFAULT; in btrfs_ioctl_balance_progress()
3732 mutex_unlock(&fs_info->balance_mutex); in btrfs_ioctl_balance_progress()
3744 return -EPERM; in btrfs_ioctl_quota_ctl()
3756 switch (sa->cmd) { in btrfs_ioctl_quota_ctl()
3759 down_write(&fs_info->subvol_sem); in btrfs_ioctl_quota_ctl()
3761 up_write(&fs_info->subvol_sem); in btrfs_ioctl_quota_ctl()
3777 * inode_lock -> subvol_sem in btrfs_ioctl_quota_ctl()
3782 * cleaner_mutex -> inode_lock -> subvol_sem in btrfs_ioctl_quota_ctl()
3788 mutex_lock(&fs_info->cleaner_mutex); in btrfs_ioctl_quota_ctl()
3789 down_write(&fs_info->subvol_sem); in btrfs_ioctl_quota_ctl()
3791 up_write(&fs_info->subvol_sem); in btrfs_ioctl_quota_ctl()
3792 mutex_unlock(&fs_info->cleaner_mutex); in btrfs_ioctl_quota_ctl()
3795 ret = -EINVAL; in btrfs_ioctl_quota_ctl()
3813 mutex_lock(&fs_info->qgroup_ioctl_lock); in qgroup_enabled()
3814 if (!fs_info->quota_root) in qgroup_enabled()
3816 mutex_unlock(&fs_info->qgroup_ioctl_lock); in qgroup_enabled()
3825 struct btrfs_root *root = BTRFS_I(inode)->root; in btrfs_ioctl_qgroup_assign()
3833 return -EPERM; in btrfs_ioctl_qgroup_assign()
3835 if (!qgroup_enabled(root->fs_info)) in btrfs_ioctl_qgroup_assign()
3836 return -ENOTCONN; in btrfs_ioctl_qgroup_assign()
3848 if (sa->assign) { in btrfs_ioctl_qgroup_assign()
3851 ret = -ENOMEM; in btrfs_ioctl_qgroup_assign()
3866 if (sa->assign) { in btrfs_ioctl_qgroup_assign()
3867 ret = btrfs_add_qgroup_relation(trans, sa->src, sa->dst, prealloc); in btrfs_ioctl_qgroup_assign()
3870 ret = btrfs_del_qgroup_relation(trans, sa->src, sa->dst); in btrfs_ioctl_qgroup_assign()
3874 mutex_lock(&fs_info->qgroup_ioctl_lock); in btrfs_ioctl_qgroup_assign()
3876 mutex_unlock(&fs_info->qgroup_ioctl_lock); in btrfs_ioctl_qgroup_assign()
3880 sa->assign ? "adding" : "deleting"); in btrfs_ioctl_qgroup_assign()
3896 struct btrfs_root *root = BTRFS_I(inode)->root; in btrfs_ioctl_qgroup_create()
3903 return -EPERM; in btrfs_ioctl_qgroup_create()
3905 if (!qgroup_enabled(root->fs_info)) in btrfs_ioctl_qgroup_create()
3906 return -ENOTCONN; in btrfs_ioctl_qgroup_create()
3918 if (!sa->qgroupid) { in btrfs_ioctl_qgroup_create()
3919 ret = -EINVAL; in btrfs_ioctl_qgroup_create()
3923 if (sa->create && is_fstree(sa->qgroupid)) { in btrfs_ioctl_qgroup_create()
3924 ret = -EINVAL; in btrfs_ioctl_qgroup_create()
3934 if (sa->create) { in btrfs_ioctl_qgroup_create()
3935 ret = btrfs_create_qgroup(trans, sa->qgroupid); in btrfs_ioctl_qgroup_create()
3937 ret = btrfs_remove_qgroup(trans, sa->qgroupid); in btrfs_ioctl_qgroup_create()
3954 struct btrfs_root *root = BTRFS_I(inode)->root; in btrfs_ioctl_qgroup_limit()
3962 return -EPERM; in btrfs_ioctl_qgroup_limit()
3964 if (!qgroup_enabled(root->fs_info)) in btrfs_ioctl_qgroup_limit()
3965 return -ENOTCONN; in btrfs_ioctl_qgroup_limit()
3983 qgroupid = sa->qgroupid; in btrfs_ioctl_qgroup_limit()
3989 ret = btrfs_limit_qgroup(trans, qgroupid, &sa->lim); in btrfs_ioctl_qgroup_limit()
4010 return -EPERM; in btrfs_ioctl_quota_rescan()
4013 return -ENOTCONN; in btrfs_ioctl_quota_rescan()
4025 if (qsa->flags) { in btrfs_ioctl_quota_rescan()
4026 ret = -EINVAL; in btrfs_ioctl_quota_rescan()
4045 return -EPERM; in btrfs_ioctl_quota_rescan_status()
4047 if (fs_info->qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_RESCAN) { in btrfs_ioctl_quota_rescan_status()
4049 qsa.progress = fs_info->qgroup_rescan_progress.objectid; in btrfs_ioctl_quota_rescan_status()
4053 return -EFAULT; in btrfs_ioctl_quota_rescan_status()
4061 return -EPERM; in btrfs_ioctl_quota_rescan_wait()
4072 struct btrfs_root *root = BTRFS_I(inode)->root; in _btrfs_ioctl_set_received_subvol()
4073 struct btrfs_root_item *root_item = &root->root_item; in _btrfs_ioctl_set_received_subvol()
4080 return -EPERM; in _btrfs_ioctl_set_received_subvol()
4086 down_write(&fs_info->subvol_sem); in _btrfs_ioctl_set_received_subvol()
4089 ret = -EINVAL; in _btrfs_ioctl_set_received_subvol()
4094 ret = -EROFS; in _btrfs_ioctl_set_received_subvol()
4099 * 1 - root item in _btrfs_ioctl_set_received_subvol()
4100 * 2 - uuid items (received uuid + subvol uuid) in _btrfs_ioctl_set_received_subvol()
4109 sa->rtransid = trans->transid; in _btrfs_ioctl_set_received_subvol()
4110 sa->rtime.sec = ct.tv_sec; in _btrfs_ioctl_set_received_subvol()
4111 sa->rtime.nsec = ct.tv_nsec; in _btrfs_ioctl_set_received_subvol()
4113 received_uuid_changed = memcmp(root_item->received_uuid, sa->uuid, in _btrfs_ioctl_set_received_subvol()
4116 !btrfs_is_empty_uuid(root_item->received_uuid)) { in _btrfs_ioctl_set_received_subvol()
4117 ret = btrfs_uuid_tree_remove(trans, root_item->received_uuid, in _btrfs_ioctl_set_received_subvol()
4120 if (ret && ret != -ENOENT) { in _btrfs_ioctl_set_received_subvol()
4126 memcpy(root_item->received_uuid, sa->uuid, BTRFS_UUID_SIZE); in _btrfs_ioctl_set_received_subvol()
4127 btrfs_set_root_stransid(root_item, sa->stransid); in _btrfs_ioctl_set_received_subvol()
4128 btrfs_set_root_rtransid(root_item, sa->rtransid); in _btrfs_ioctl_set_received_subvol()
4129 btrfs_set_stack_timespec_sec(&root_item->stime, sa->stime.sec); in _btrfs_ioctl_set_received_subvol()
4130 btrfs_set_stack_timespec_nsec(&root_item->stime, sa->stime.nsec); in _btrfs_ioctl_set_received_subvol()
4131 btrfs_set_stack_timespec_sec(&root_item->rtime, sa->rtime.sec); in _btrfs_ioctl_set_received_subvol()
4132 btrfs_set_stack_timespec_nsec(&root_item->rtime, sa->rtime.nsec); in _btrfs_ioctl_set_received_subvol()
4134 ret = btrfs_update_root(trans, fs_info->tree_root, in _btrfs_ioctl_set_received_subvol()
4135 &root->root_key, &root->root_item); in _btrfs_ioctl_set_received_subvol()
4140 if (received_uuid_changed && !btrfs_is_empty_uuid(sa->uuid)) { in _btrfs_ioctl_set_received_subvol()
4141 ret = btrfs_uuid_tree_add(trans, sa->uuid, in _btrfs_ioctl_set_received_subvol()
4144 if (ret < 0 && ret != -EEXIST) { in _btrfs_ioctl_set_received_subvol()
4152 up_write(&fs_info->subvol_sem); in _btrfs_ioctl_set_received_subvol()
4171 ret = -ENOMEM; in btrfs_ioctl_set_received_subvol_32()
4175 memcpy(args64->uuid, args32->uuid, BTRFS_UUID_SIZE); in btrfs_ioctl_set_received_subvol_32()
4176 args64->stransid = args32->stransid; in btrfs_ioctl_set_received_subvol_32()
4177 args64->rtransid = args32->rtransid; in btrfs_ioctl_set_received_subvol_32()
4178 args64->stime.sec = args32->stime.sec; in btrfs_ioctl_set_received_subvol_32()
4179 args64->stime.nsec = args32->stime.nsec; in btrfs_ioctl_set_received_subvol_32()
4180 args64->rtime.sec = args32->rtime.sec; in btrfs_ioctl_set_received_subvol_32()
4181 args64->rtime.nsec = args32->rtime.nsec; in btrfs_ioctl_set_received_subvol_32()
4182 args64->flags = args32->flags; in btrfs_ioctl_set_received_subvol_32()
4188 memcpy(args32->uuid, args64->uuid, BTRFS_UUID_SIZE); in btrfs_ioctl_set_received_subvol_32()
4189 args32->stransid = args64->stransid; in btrfs_ioctl_set_received_subvol_32()
4190 args32->rtransid = args64->rtransid; in btrfs_ioctl_set_received_subvol_32()
4191 args32->stime.sec = args64->stime.sec; in btrfs_ioctl_set_received_subvol_32()
4192 args32->stime.nsec = args64->stime.nsec; in btrfs_ioctl_set_received_subvol_32()
4193 args32->rtime.sec = args64->rtime.sec; in btrfs_ioctl_set_received_subvol_32()
4194 args32->rtime.nsec = args64->rtime.nsec; in btrfs_ioctl_set_received_subvol_32()
4195 args32->flags = args64->flags; in btrfs_ioctl_set_received_subvol_32()
4199 ret = -EFAULT; in btrfs_ioctl_set_received_subvol_32()
4225 ret = -EFAULT; in btrfs_ioctl_set_received_subvol()
4239 spin_lock(&fs_info->super_lock); in btrfs_ioctl_get_fslabel()
4240 memcpy(label, fs_info->super_copy->label, BTRFS_LABEL_SIZE); in btrfs_ioctl_get_fslabel()
4241 spin_unlock(&fs_info->super_lock); in btrfs_ioctl_get_fslabel()
4248 --len); in btrfs_ioctl_get_fslabel()
4253 return ret ? -EFAULT : 0; in btrfs_ioctl_get_fslabel()
4260 struct btrfs_root *root = BTRFS_I(inode)->root; in btrfs_ioctl_set_fslabel()
4261 struct btrfs_super_block *super_block = fs_info->super_copy; in btrfs_ioctl_set_fslabel()
4267 return -EPERM; in btrfs_ioctl_set_fslabel()
4270 return -EFAULT; in btrfs_ioctl_set_fslabel()
4275 BTRFS_LABEL_SIZE - 1); in btrfs_ioctl_set_fslabel()
4276 return -EINVAL; in btrfs_ioctl_set_fslabel()
4289 spin_lock(&fs_info->super_lock); in btrfs_ioctl_set_fslabel()
4290 strcpy(super_block->label, label); in btrfs_ioctl_set_fslabel()
4291 spin_unlock(&fs_info->super_lock); in btrfs_ioctl_set_fslabel()
4313 return -EFAULT; in btrfs_ioctl_get_supported_features()
4321 struct btrfs_super_block *super_block = fs_info->super_copy; in btrfs_ioctl_get_features()
4329 return -EFAULT; in btrfs_ioctl_get_features()
4357 return -EOPNOTSUPP; in check_feature_bits()
4372 return -EPERM; in check_feature_bits()
4387 return -EPERM; in check_feature_bits()
4403 struct btrfs_root *root = BTRFS_I(inode)->root; in btrfs_ioctl_set_features()
4404 struct btrfs_super_block *super_block = fs_info->super_copy; in btrfs_ioctl_set_features()
4411 return -EPERM; in btrfs_ioctl_set_features()
4414 return -EFAULT; in btrfs_ioctl_set_features()
4446 spin_lock(&fs_info->super_lock); in btrfs_ioctl_set_features()
4461 spin_unlock(&fs_info->super_lock); in btrfs_ioctl_set_features()
4481 return -EFAULT; in _btrfs_ioctl_send()
4484 return -ENOMEM; in _btrfs_ioctl_send()
4485 arg->send_fd = args32.send_fd; in _btrfs_ioctl_send()
4486 arg->clone_sources_count = args32.clone_sources_count; in _btrfs_ioctl_send()
4487 arg->clone_sources = compat_ptr(args32.clone_sources); in _btrfs_ioctl_send()
4488 arg->parent_root = args32.parent_root; in _btrfs_ioctl_send()
4489 arg->flags = args32.flags; in _btrfs_ioctl_send()
4490 arg->version = args32.version; in _btrfs_ioctl_send()
4491 memcpy(arg->reserved, args32.reserved, in _btrfs_ioctl_send()
4494 return -ENOTTY; in _btrfs_ioctl_send()
4514 struct btrfs_fs_info *fs_info = inode->root->fs_info; in btrfs_ioctl_encoded_read()
4515 struct extent_io_tree *io_tree = &inode->io_tree; in btrfs_ioctl_encoded_read()
4526 ret = -EPERM; in btrfs_ioctl_encoded_read()
4537 ret = -EFAULT; in btrfs_ioctl_encoded_read()
4545 return -ENOTTY; in btrfs_ioctl_encoded_read()
4550 ret = -EFAULT; in btrfs_ioctl_encoded_read()
4555 ret = -EINVAL; in btrfs_ioctl_encoded_read()
4579 if (ret == -EIOCBQUEUED) { in btrfs_ioctl_encoded_read()
4583 start = ALIGN_DOWN(kiocb.ki_pos, fs_info->sectorsize); in btrfs_ioctl_encoded_read()
4584 lockend = start + BTRFS_MAX_UNCOMPRESSED - 1; in btrfs_ioctl_encoded_read()
4606 sizeof(args) - copy_end_kernel)) in btrfs_ioctl_encoded_read()
4607 ret = -EFAULT; in btrfs_ioctl_encoded_read()
4630 ret = -EPERM; in btrfs_ioctl_encoded_write()
4634 if (!(file->f_mode & FMODE_WRITE)) { in btrfs_ioctl_encoded_write()
4635 ret = -EBADF; in btrfs_ioctl_encoded_write()
4644 ret = -EFAULT; in btrfs_ioctl_encoded_write()
4658 return -ENOTTY; in btrfs_ioctl_encoded_write()
4662 ret = -EFAULT; in btrfs_ioctl_encoded_write()
4667 ret = -EINVAL; in btrfs_ioctl_encoded_write()
4680 if (args.len > args.unencoded_len - args.unencoded_offset) in btrfs_ioctl_encoded_write()
4720 * Context that's attached to an encoded read io_uring command, in cmd->pdu. It
4746 struct btrfs_uring_priv *priv = bc->priv; in btrfs_uring_read_finished()
4747 struct btrfs_inode *inode = BTRFS_I(file_inode(priv->iocb.ki_filp)); in btrfs_uring_read_finished()
4748 struct extent_io_tree *io_tree = &inode->io_tree; in btrfs_uring_read_finished()
4757 if (priv->err) { in btrfs_uring_read_finished()
4758 ret = priv->err; in btrfs_uring_read_finished()
4762 if (priv->compressed) { in btrfs_uring_read_finished()
4766 index = (priv->iocb.ki_pos - priv->start) >> PAGE_SHIFT; in btrfs_uring_read_finished()
4767 page_offset = offset_in_page(priv->iocb.ki_pos - priv->start); in btrfs_uring_read_finished()
4770 while (cur < priv->count) { in btrfs_uring_read_finished()
4771 size_t bytes = min_t(size_t, priv->count - cur, PAGE_SIZE - page_offset); in btrfs_uring_read_finished()
4773 if (copy_page_to_iter(priv->pages[index], page_offset, bytes, in btrfs_uring_read_finished()
4774 &priv->iter) != bytes) { in btrfs_uring_read_finished()
4775 ret = -EFAULT; in btrfs_uring_read_finished()
4783 ret = priv->count; in btrfs_uring_read_finished()
4786 unlock_extent(io_tree, priv->start, priv->lockend, &priv->cached_state); in btrfs_uring_read_finished()
4792 for (index = 0; index < priv->nr_pages; index++) in btrfs_uring_read_finished()
4793 __free_page(priv->pages[index]); in btrfs_uring_read_finished()
4795 kfree(priv->pages); in btrfs_uring_read_finished()
4796 kfree(priv->iov); in btrfs_uring_read_finished()
4803 struct io_btrfs_cmd *bc = io_uring_cmd_to_pdu(priv->cmd, struct io_btrfs_cmd); in btrfs_uring_read_extent_endio()
4805 priv->err = err; in btrfs_uring_read_extent_endio()
4806 bc->priv = priv; in btrfs_uring_read_extent_endio()
4808 io_uring_cmd_complete_in_task(priv->cmd, btrfs_uring_read_finished); in btrfs_uring_read_extent_endio()
4818 struct btrfs_inode *inode = BTRFS_I(file_inode(iocb->ki_filp)); in btrfs_uring_read_extent()
4819 struct extent_io_tree *io_tree = &inode->io_tree; in btrfs_uring_read_extent()
4828 return -ENOMEM; in btrfs_uring_read_extent()
4831 ret = -ENOMEM; in btrfs_uring_read_extent()
4837 ret = -ENOMEM; in btrfs_uring_read_extent()
4841 priv->iocb = *iocb; in btrfs_uring_read_extent()
4842 priv->iov = iov; in btrfs_uring_read_extent()
4843 priv->iter = *iter; in btrfs_uring_read_extent()
4844 priv->count = count; in btrfs_uring_read_extent()
4845 priv->cmd = cmd; in btrfs_uring_read_extent()
4846 priv->cached_state = cached_state; in btrfs_uring_read_extent()
4847 priv->compressed = compressed; in btrfs_uring_read_extent()
4848 priv->nr_pages = nr_pages; in btrfs_uring_read_extent()
4849 priv->pages = pages; in btrfs_uring_read_extent()
4850 priv->start = start; in btrfs_uring_read_extent()
4851 priv->lockend = lockend; in btrfs_uring_read_extent()
4852 priv->err = 0; in btrfs_uring_read_extent()
4856 if (ret && ret != -EIOCBQUEUED) in btrfs_uring_read_extent()
4860 * If we return -EIOCBQUEUED, we're deferring the cleanup to in btrfs_uring_read_extent()
4867 * okay - it'll get unlocked in a worker thread. Call in btrfs_uring_read_extent()
4872 return -EIOCBQUEUED; in btrfs_uring_read_extent()
4902 ret = -EPERM; in btrfs_uring_encoded_read()
4905 file = cmd->file; in btrfs_uring_encoded_read()
4906 inode = BTRFS_I(file->f_inode); in btrfs_uring_encoded_read()
4907 fs_info = inode->root->fs_info; in btrfs_uring_encoded_read()
4908 io_tree = &inode->io_tree; in btrfs_uring_encoded_read()
4909 sqe_addr = u64_to_user_ptr(READ_ONCE(cmd->sqe->addr)); in btrfs_uring_encoded_read()
4917 ret = -EFAULT; in btrfs_uring_encoded_read()
4925 return -ENOTTY; in btrfs_uring_encoded_read()
4930 ret = -EFAULT; in btrfs_uring_encoded_read()
4936 return -EINVAL; in btrfs_uring_encoded_read()
4959 start = ALIGN_DOWN(pos, fs_info->sectorsize); in btrfs_uring_encoded_read()
4960 lockend = start + BTRFS_MAX_UNCOMPRESSED - 1; in btrfs_uring_encoded_read()
4964 if (ret < 0 && ret != -EIOCBQUEUED) in btrfs_uring_encoded_read()
4970 sizeof(args) - copy_end_kernel)) { in btrfs_uring_encoded_read()
4971 if (ret == -EIOCBQUEUED) { in btrfs_uring_encoded_read()
4975 ret = -EFAULT; in btrfs_uring_encoded_read()
4979 if (ret == -EIOCBQUEUED) { in btrfs_uring_encoded_read()
4991 ret = -ENOMEM; in btrfs_uring_encoded_read()
5025 switch (cmd->cmd_op) { in btrfs_uring_cmd()
5033 return -EINVAL; in btrfs_uring_cmd()
5047 return -EFAULT; in btrfs_ioctl_subvol_sync()
5055 spin_lock(&fs_info->trans_lock); in btrfs_ioctl_subvol_sync()
5056 if (!list_empty(&fs_info->dead_roots)) { in btrfs_ioctl_subvol_sync()
5057 root = list_last_entry(&fs_info->dead_roots, in btrfs_ioctl_subvol_sync()
5062 spin_unlock(&fs_info->trans_lock); in btrfs_ioctl_subvol_sync()
5064 return -ENOENT; in btrfs_ioctl_subvol_sync()
5070 return -EINVAL; in btrfs_ioctl_subvol_sync()
5073 spin_lock(&fs_info->trans_lock); in btrfs_ioctl_subvol_sync()
5074 args.count = list_count_nodes(&fs_info->dead_roots); in btrfs_ioctl_subvol_sync()
5075 spin_unlock(&fs_info->trans_lock); in btrfs_ioctl_subvol_sync()
5077 return -EFAULT; in btrfs_ioctl_subvol_sync()
5080 spin_lock(&fs_info->trans_lock); in btrfs_ioctl_subvol_sync()
5082 if (!list_empty(&fs_info->dead_roots)) { in btrfs_ioctl_subvol_sync()
5083 root = list_last_entry(&fs_info->dead_roots, in btrfs_ioctl_subvol_sync()
5089 spin_unlock(&fs_info->trans_lock); in btrfs_ioctl_subvol_sync()
5091 return -EFAULT; in btrfs_ioctl_subvol_sync()
5094 spin_lock(&fs_info->trans_lock); in btrfs_ioctl_subvol_sync()
5096 if (!list_empty(&fs_info->dead_roots)) { in btrfs_ioctl_subvol_sync()
5097 root = list_first_entry(&fs_info->dead_roots, in btrfs_ioctl_subvol_sync()
5103 spin_unlock(&fs_info->trans_lock); in btrfs_ioctl_subvol_sync()
5105 return -EFAULT; in btrfs_ioctl_subvol_sync()
5108 return -EINVAL; in btrfs_ioctl_subvol_sync()
5113 return -EOVERFLOW; in btrfs_ioctl_subvol_sync()
5117 if (down_read_interruptible(&fs_info->subvol_sem) == -EINTR) in btrfs_ioctl_subvol_sync()
5118 return -EINTR; in btrfs_ioctl_subvol_sync()
5119 refs = -1; in btrfs_ioctl_subvol_sync()
5120 spin_lock(&fs_info->fs_roots_radix_lock); in btrfs_ioctl_subvol_sync()
5121 root = radix_tree_lookup(&fs_info->fs_roots_radix, in btrfs_ioctl_subvol_sync()
5124 spin_lock(&root->root_item_lock); in btrfs_ioctl_subvol_sync()
5125 refs = btrfs_root_refs(&root->root_item); in btrfs_ioctl_subvol_sync()
5126 root_flags = btrfs_root_flags(&root->root_item); in btrfs_ioctl_subvol_sync()
5127 spin_unlock(&root->root_item_lock); in btrfs_ioctl_subvol_sync()
5129 spin_unlock(&fs_info->fs_roots_radix_lock); in btrfs_ioctl_subvol_sync()
5130 up_read(&fs_info->subvol_sem); in btrfs_ioctl_subvol_sync()
5134 return -ENOENT; in btrfs_ioctl_subvol_sync()
5138 return -EEXIST; in btrfs_ioctl_subvol_sync()
5140 if (wait_for_deletion && refs == -1) { in btrfs_ioctl_subvol_sync()
5143 return -EFAULT; in btrfs_ioctl_subvol_sync()
5148 if (refs == -1) in btrfs_ioctl_subvol_sync()
5149 return -ENOENT; in btrfs_ioctl_subvol_sync()
5156 return -EINTR; in btrfs_ioctl_subvol_sync()
5167 struct btrfs_root *root = BTRFS_I(inode)->root; in btrfs_ioctl()
5233 ret = btrfs_sync_fs(inode->i_sb, 1); in btrfs_ioctl()
5238 wake_up_process(fs_info->cleaner_kthread); in btrfs_ioctl()
5317 return -ENOTTY; in btrfs_ioctl()
5324 * These all access 32-bit values anyway so no further in btrfs_compat_ioctl()