New qgroup creation / removal ioctls
v3 cover New qgroup creation / removal ioctls
This patch introduces two new ioctls for creating, and removing qgroups. These ioctls have a new args structure that allows passing flags, and some reserved fields for future expansion. The ioctls prevent some operations around level-0 qgroups as well.
The create operation prevents the creation of level-0 qgroups for subvolumes that do not exist. The delete operations prevents the deletion of level-0 qgroups that reference active volumes.
There are two different ioctl for creation, and deletion to enable filtering of the ioctls via tools like seccomp-bpf. Currently, there is one "swiss-army" ioctl that's multiplexed for creation, and deletion, and you need to be able to dereference user memory to determine whether or not it's a destructive operation -- something that cannot be done via seccomp nor LSMs.
Changes since v2:
* Use a common datastructure for removal and creation
* Remove deprecation message for old API
Changes since v1:
* Remove creation of level-0 qgroups without subvol
Sargun Dhillon (2):
btrfs: Fail on removing qgroup if del_qgroup_item fails
btrfs: Add new ioctl uapis for qgroup creation / removal
fs/btrfs/ioctl.c | 100 ++++++++++++++++++++++++++++++++++++++++++++- fs/btrfs/qgroup.c | 79 ++++++++++++++++++++++++++++++++--- fs/btrfs/qgroup.h | 6 ++- include/uapi/linux/btrfs.h | 16 ++++++++ 4 files changed, 192 insertions(+), 9 deletions(-)
Signature · 1 line
2.9.3
PATCH v3 1/2 btrfs: Fail on removing qgroup if del_qgroup_item fails
Previously, we were calling del_qgroup_item, and ignoring the return code resulting in a potential to have divergent in-memory state without an error. Perhaps, it makes sense to handle this error code, and put the filesystem into a read only, or similar state.
This patch only adds reporting of the error if the error is fatal, (any error other than qgroup not found).
--- fs/btrfs/qgroup.c | 3 +++ 1 file changed, 3 insertions(+)
fs/btrfs/qgroup.c +3 -0
@@ -1309,6 +1309,9 @@ int btrfs_remove_qgroup(struct btrfs_trans_handle *trans, } ret =del_qgroup_item (trans, quota_root, qgroupid); +if (ret && ret != -ENOENT ) + goto out; +while (!list_empty (&qgroup->groups)) { list =list_first_entry (&qgroup->groups, struct btrfs_qgroup_list, next_group);
Signature · 1 line
2.9.3
PATCH v3 2/2 btrfs: Add new ioctl uapis for qgroup creation / removal
In reply to Sargun DhillonThis patch introduces two new ioctls to create, and remove qgroups. These offer a somewhat more intuitive set of operations with the opportunity to add flags that gate to unintentional manipulation of qgroups.
The create qgroup ioctl has a a new semantic which level-0 qgroups cannot be created unless a matching subvolume ID is created.
The delete qgroup ioctl has the new semantic that it will not let you delete a currently utilized (referenced by a subvolume) level-0 qgroup unless you pass the BTRFS_QGROUP_NO_SUBVOL_CHECK flag.
--- fs/btrfs/ioctl.c | 100 ++++++++++++++++++++++++++++++++++++++++++++- fs/btrfs/qgroup.c | 76 +++++++++++++++++++++++++++++++--- fs/btrfs/qgroup.h | 6 ++- include/uapi/linux/btrfs.h | 16 ++++++++ 4 files changed, 189 insertions(+), 9 deletions(-)
fs/btrfs/ioctl.c +98 -2
@@ -4924,6 +4924,98 @@ static long btrfs_ioctl_qgroup_assign(struct file *file, void __user *arg)return ret; } +static long btrfs_ioctl_qgroup_create_v2 (struct file *file,void __user *uargs) +{ +struct btrfs_ioctl_qgroup_args_v2 args; +struct btrfs_trans_handle *trans; +struct btrfs_fs_info *fs_info; +struct btrfs_root *root; +struct inode *inode; +int ret; +int err; + + inode =file_inode (file); + fs_info =btrfs_sb (inode->i_sb); + root =BTRFS_I (inode)->root; + +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ; + + ret =copy_from_user (&args, uargs,sizeof (args)); +if (ret) +return ret; + +if (!args.qgroupid) +return -EINVAL ; + + ret =mnt_want_write_file (file); +if (ret) +return ret; + + trans =btrfs_join_transaction (root); +if (IS_ERR (trans)) { + ret =PTR_ERR (trans); + goto out; + } + + ret =btrfs_create_qgroup (trans, fs_info, args.qgroupid,1 ); + err =btrfs_end_transaction (trans); + +if (err && !ret) + ret = err; + +out: +mnt_drop_write_file (file); +return ret; +} + +static long btrfs_ioctl_qgroup_remove_v2 (struct file *file,void __user *uargs) +{ +struct btrfs_ioctl_qgroup_args_v2 args; +struct btrfs_trans_handle *trans; +struct btrfs_fs_info *fs_info; +struct btrfs_root *root; +struct inode *inode; +int check; +int ret; +int err; + + inode =file_inode (file); + fs_info =btrfs_sb (inode->i_sb); + root =BTRFS_I (inode)->root; + +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ; + + ret =copy_from_user (&args, uargs,sizeof (args)); +if (ret) +return ret; + +if (!args.qgroupid) +return -EINVAL ; + check = !(args.flags &BTRFS_QGROUP_NO_SUBVOL_CHECK ); + + ret =mnt_want_write_file (file); +if (ret) +return ret; + + trans =btrfs_join_transaction (root); +if (IS_ERR (trans)) { + ret =PTR_ERR (trans); + goto out; + } + + ret =btrfs_remove_qgroup (trans, fs_info, args.qgroupid, check); + err =btrfs_end_transaction (trans); + +if (err && !ret) + ret = err; + +out: +mnt_drop_write_file (file); +return ret; +} +static long btrfs_ioctl_qgroup_create (struct file *file,void __user *arg) {struct inode *inode =file_inode (file);
@@ -4959,9 +5051,9 @@ static long btrfs_ioctl_qgroup_create(struct file *file, void __user *arg) }if (sa->create) { - ret =btrfs_create_qgroup (trans, fs_info, sa->qgroupid); + ret =btrfs_create_qgroup (trans, fs_info, sa->qgroupid,0 ); }else { - ret =btrfs_remove_qgroup (trans, fs_info, sa->qgroupid); + ret =btrfs_remove_qgroup (trans, fs_info, sa->qgroupid,0 ); } err =btrfs_end_transaction (trans);
@@ -5632,6 +5724,10 @@ long btrfs_ioctl(struct file *file, unsigned intreturn btrfs_ioctl_get_features (file, argp);case BTRFS_IOC_SET_FEATURES :return btrfs_ioctl_set_features (file, argp); +case BTRFS_IOC_QGROUP_CREATE_V2 : +return btrfs_ioctl_qgroup_create_v2 (file, argp); +case BTRFS_IOC_QGROUP_REMOVE_V2 : +return btrfs_ioctl_qgroup_remove_v2 (file, argp); }return -ENOTTY ;
fs/btrfs/qgroup.c +71 -5
111 lines not on this page · raw message
fs/btrfs/qgroup.h +4 -2
@@ -125,9 +125,11 @@ int btrfs_add_qgroup_relation(struct btrfs_trans_handle *trans,int btrfs_del_qgroup_relation (struct btrfs_trans_handle *trans,struct btrfs_fs_info *fs_info,u64 src,u64 dst);int btrfs_create_qgroup (struct btrfs_trans_handle *trans, -struct btrfs_fs_info *fs_info,u64 qgroupid); +struct btrfs_fs_info *fs_info,u64 qgroupid, +int check_subvol_exists);int btrfs_remove_qgroup (struct btrfs_trans_handle *trans, -struct btrfs_fs_info *fs_info,u64 qgroupid); +struct btrfs_fs_info *fs_info,u64 qgroupid, +int check_subvol_exists);int btrfs_limit_qgroup (struct btrfs_trans_handle *trans,struct btrfs_fs_info *fs_info,u64 qgroupid,struct btrfs_qgroup_limit *limit);
include/uapi/linux/btrfs.h +16 -0
@@ -676,6 +676,18 @@ struct btrfs_ioctl_qgroup_create_args {__u64 create;__u64 qgroupid; }; + +/* +* Allows for the deletion of qgroups even if they are associated with active +* volumes. +*/ +#define BTRFS_QGROUP_NO_SUBVOL_CHECK (1ULL << 0) +struct btrfs_ioctl_qgroup_args_v2 { +__u64 qgroupid; +__u64 flags; +__u64 reserved[16 ]; +}; +struct btrfs_ioctl_timespec {__u64 sec;__u32 nsec;
@@ -841,5 +853,9 @@ enum btrfs_err_code { struct btrfs_ioctl_feature_flags[3])#define BTRFS_IOC_RM_DEV_V2 _IOW(BTRFS_IOCTL_MAGIC, 58, \ struct btrfs_ioctl_vol_args_v2) +#define BTRFS_IOC_QGROUP_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 59, \ + struct btrfs_ioctl_qgroup_args_v2) +#define BTRFS_IOC_QGROUP_REMOVE_V2 _IOW(BTRFS_IOCTL_MAGIC, 60, \ + struct btrfs_ioctl_qgroup_args_v2)#endif /* _UAPI_LINUX_BTRFS_H */
Signature · 1 line
2.9.3
kbuild test robot
build botRe: [PATCH v3 2/2] btrfs: Add new ioctl uapis for qgroup creation / removal
url: https://github.com/0day-ci/linux/commits/Sargun-Dhillon/New-qgroup-creation-removal-ioctls/20170715-195435 config: xtensa-allyesconfig (attached as .config) compiler: xtensa-linux-gcc (GCC)…
Hi Sargun,
[auto build test ERROR on linus/master]
[also build test ERROR on v4.12 next-20170714]
[cannot apply to btrfs/next]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Sargun-Dhillon/New-qgroup-creation-removal-ioctls/20170715-195435
config: xtensa-allyesconfig (attached as .config)
compiler: xtensa-linux-gcc (GCC) 4.9.0
reproduce:
wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=xtensa
All errors (new ones prefixed by >>):
fs/btrfs/tests/qgroup-tests.c: In function 'test_no_shared_qgroup':
>> fs/btrfs/tests/qgroup-tests.c:232:8: error: too few arguments to function 'btrfs_create_qgroup'
ret = btrfs_create_qgroup(NULL, fs_info, BTRFS_FS_TREE_OBJECTID);
^
In file included from fs/btrfs/tests/qgroup-tests.c:24:0:
fs/btrfs/tests/../qgroup.h:127:5: note: declared here
int btrfs_create_qgroup(struct btrfs_trans_handle *trans,
^
fs/btrfs/tests/qgroup-tests.c: In function 'test_multiple_refs':
fs/btrfs/tests/qgroup-tests.c:334:8: error: too few arguments to function 'btrfs_create_qgroup'
ret = btrfs_create_qgroup(NULL, fs_info, BTRFS_FIRST_FREE_OBJECTID);
^ In file included from fs/btrfs/tests/qgroup-tests.c:24:0:
fs/btrfs/tests/../qgroup.h:127:5: note: declared here
int btrfs_create_qgroup(struct btrfs_trans_handle *trans,
^
vim +/btrfs_create_qgroup +232 fs/btrfs/tests/qgroup-tests.c
faa2dbf0 Josef Bacik 2014-05-07 219
b9ef22de Feifei Xu 2016-06-01 220 static int test_no_shared_qgroup(struct btrfs_root *root,
b9ef22de Feifei Xu 2016-06-01 221 u32 sectorsize, u32 nodesize)
faa2dbf0 Josef Bacik 2014-05-07 222 {
faa2dbf0 Josef Bacik 2014-05-07 223 struct btrfs_trans_handle trans;
faa2dbf0 Josef Bacik 2014-05-07 224 struct btrfs_fs_info *fs_info = root->fs_info;
442244c9 Qu Wenruo 2015-04-16 225 struct ulist *old_roots = NULL;
442244c9 Qu Wenruo 2015-04-16 226 struct ulist *new_roots = NULL;
faa2dbf0 Josef Bacik 2014-05-07 227 int ret;
faa2dbf0 Josef Bacik 2014-05-07 228
7c55ee0c Omar Sandoval 2015-09-29 229 btrfs_init_dummy_trans(&trans);
faa2dbf0 Josef Bacik 2014-05-07 230
faa2dbf0 Josef Bacik 2014-05-07 231 test_msg("Qgroup basic add\n");
ef9f2db3 Feifei Xu 2016-06-01 @232 ret = btrfs_create_qgroup(NULL, fs_info, BTRFS_FS_TREE_OBJECTID);
faa2dbf0 Josef Bacik 2014-05-07 233 if (ret) {
faa2dbf0 Josef Bacik 2014-05-07 234 test_msg("Couldn't create a qgroup %d\n", ret);
faa2dbf0 Josef Bacik 2014-05-07 235 return ret;
faa2dbf0 Josef Bacik 2014-05-07 236 }
faa2dbf0 Josef Bacik 2014-05-07 237
442244c9 Qu Wenruo 2015-04-16 238 /*
01327610 Nicholas D Steeves 2016-05-19 239 * Since the test trans doesn't have the complicated delayed refs,
442244c9 Qu Wenruo 2015-04-16 240 * we can only call btrfs_qgroup_account_extent() directly to test
442244c9 Qu Wenruo 2015-04-16 241 * quota.
442244c9 Qu Wenruo 2015-04-16 242 */
b9ef22de Feifei Xu 2016-06-01 243 ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &old_roots);
faa2dbf0 Josef Bacik 2014-05-07 244 if (ret) {
442244c9 Qu Wenruo 2015-04-16 245 ulist_free(old_roots);
442244c9 Qu Wenruo 2015-04-16 246 test_msg("Couldn't find old roots: %d\n", ret);
faa2dbf0 Josef Bacik 2014-05-07 247 return ret;
faa2dbf0 Josef Bacik 2014-05-07 248 }
faa2dbf0 Josef Bacik 2014-05-07 249
ef9f2db3 Feifei Xu 2016-06-01 250 ret = insert_normal_tree_ref(root, nodesize, nodesize, 0,
ef9f2db3 Feifei Xu 2016-06-01 251 BTRFS_FS_TREE_OBJECTID);
faa2dbf0 Josef Bacik 2014-05-07 252 if (ret)
faa2dbf0 Josef Bacik 2014-05-07 253 return ret;
faa2dbf0 Josef Bacik 2014-05-07 254
b9ef22de Feifei Xu 2016-06-01 255 ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &new_roots);
442244c9 Qu Wenruo 2015-04-16 256 if (ret) {
442244c9 Qu Wenruo 2015-04-16 257 ulist_free(old_roots);
442244c9 Qu Wenruo 2015-04-16 258 ulist_free(new_roots);
442244c9 Qu Wenruo 2015-04-16 259 test_msg("Couldn't find old roots: %d\n", ret);
442244c9 Qu Wenruo 2015-04-16 260 return ret;
442244c9 Qu Wenruo 2015-04-16 261 }
442244c9 Qu Wenruo 2015-04-16 262
b9ef22de Feifei Xu 2016-06-01 263 ret = btrfs_qgroup_account_extent(&trans, fs_info, nodesize,
b9ef22de Feifei Xu 2016-06-01 264 nodesize, old_roots, new_roots);
faa2dbf0 Josef Bacik 2014-05-07 265 if (ret) {
442244c9 Qu Wenruo 2015-04-16 266 test_msg("Couldn't account space for a qgroup %d\n", ret);
faa2dbf0 Josef Bacik 2014-05-07 267 return ret;
faa2dbf0 Josef Bacik 2014-05-07 268 }
faa2dbf0 Josef Bacik 2014-05-07 269
ef9f2db3 Feifei Xu 2016-06-01 270 if (btrfs_verify_qgroup_counts(fs_info, BTRFS_FS_TREE_OBJECTID,
ef9f2db3 Feifei Xu 2016-06-01 271 nodesize, nodesize)) {
faa2dbf0 Josef Bacik 2014-05-07 272 test_msg("Qgroup counts didn't match expected values\n");
faa2dbf0 Josef Bacik 2014-05-07 273 return -EINVAL;
faa2dbf0 Josef Bacik 2014-05-07 274 }
442244c9 Qu Wenruo 2015-04-16 275 old_roots = NULL;
442244c9 Qu Wenruo 2015-04-16 276 new_roots = NULL;
442244c9 Qu Wenruo 2015-04-16 277
b9ef22de Feifei Xu 2016-06-01 278 ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &old_roots);
442244c9 Qu Wenruo 2015-04-16 279 if (ret) {
442244c9 Qu Wenruo 2015-04-16 280 ulist_free(old_roots);
442244c9 Qu Wenruo 2015-04-16 281 test_msg("Couldn't find old roots: %d\n", ret);
442244c9 Qu Wenruo 2015-04-16 282 return ret;
442244c9 Qu Wenruo 2015-04-16 283 }
faa2dbf0 Josef Bacik 2014-05-07 284
b9ef22de Feifei Xu 2016-06-01 285 ret = remove_extent_item(root, nodesize, nodesize);
faa2dbf0 Josef Bacik 2014-05-07 286 if (ret)
faa2dbf0 Josef Bacik 2014-05-07 287 return -EINVAL;
faa2dbf0 Josef Bacik 2014-05-07 288
b9ef22de Feifei Xu 2016-06-01 289 ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &new_roots);
faa2dbf0 Josef Bacik 2014-05-07 290 if (ret) {
442244c9 Qu Wenruo 2015-04-16 291 ulist_free(old_roots);
442244c9 Qu Wenruo 2015-04-16 292 ulist_free(new_roots);
442244c9 Qu Wenruo 2015-04-16 293 test_msg("Couldn't find old roots: %d\n", ret);
442244c9 Qu Wenruo 2015-04-16 294 return ret;
faa2dbf0 Josef Bacik 2014-05-07 295 }
faa2dbf0 Josef Bacik 2014-05-07 296
b9ef22de Feifei Xu 2016-06-01 297 ret = btrfs_qgroup_account_extent(&trans, fs_info, nodesize,
b9ef22de Feifei Xu 2016-06-01 298 nodesize, old_roots, new_roots);
faa2dbf0 Josef Bacik 2014-05-07 299 if (ret) {
442244c9 Qu Wenruo 2015-04-16 300 test_msg("Couldn't account space for a qgroup %d\n", ret);
faa2dbf0 Josef Bacik 2014-05-07 301 return -EINVAL;
faa2dbf0 Josef Bacik 2014-05-07 302 }
faa2dbf0 Josef Bacik 2014-05-07 303
ef9f2db3 Feifei Xu 2016-06-01 304 if (btrfs_verify_qgroup_counts(fs_info, BTRFS_FS_TREE_OBJECTID, 0, 0)) {
faa2dbf0 Josef Bacik 2014-05-07 305 test_msg("Qgroup counts didn't match expected values\n");
faa2dbf0 Josef Bacik 2014-05-07 306 return -EINVAL;
faa2dbf0 Josef Bacik 2014-05-07 307 }
faa2dbf0 Josef Bacik 2014-05-07 308
faa2dbf0 Josef Bacik 2014-05-07 309 return 0;
faa2dbf0 Josef Bacik 2014-05-07 310 }
faa2dbf0 Josef Bacik 2014-05-07 311 :::::: The code at line 232 was first introduced by commit
:::::: ef9f2db365c31433e52b0c5863793273bb632666 Btrfs: self-tests: Use macros instead of constants and add missing newline
:::::: TO: Feifei Xu <[email protected]> :::::: CC: David Sterba <[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
kbuild test robot
build botRe: [PATCH v3 2/2] btrfs: Add new ioctl uapis for qgroup creation / removal
In reply to Sargun Dhillonurl: https://github.com/0day-ci/linux/commits/Sargun-Dhillon/New-qgroup-creation-removal-ioctls/20170715-195435 reproduce:
Hi Sargun,
[auto build test WARNING on linus/master]
[also build test WARNING on v4.13-rc1 next-20170717]
[cannot apply to btrfs/next]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Sargun-Dhillon/New-qgroup-creation-removal-ioctls/20170715-195435
reproduce:
# apt-get install sparse
make ARCH=x86_64 allmodconfig
make C=1 CF=-D__CHECK_ENDIAN__sparse warnings: (new ones prefixed by >>)
include/linux/compiler.h:260:8: sparse: attribute 'no_sanitize_address': unknown attribute
>> fs/btrfs/tests/qgroup-tests.c:232:34: sparse: not enough arguments for function btrfs_create_qgroup
fs/btrfs/tests/qgroup-tests.c:334:34: sparse: not enough arguments for function btrfs_create_qgroup
fs/btrfs/tests/qgroup-tests.c: In function 'test_no_shared_qgroup':
fs/btrfs/tests/qgroup-tests.c:232:8: error: too few arguments to function 'btrfs_create_qgroup'
ret = btrfs_create_qgroup(NULL, fs_info, BTRFS_FS_TREE_OBJECTID);
^~~~~~~~~~~~~~~~~~~
In file included from fs/btrfs/tests/qgroup-tests.c:24:0:
fs/btrfs/tests/../qgroup.h:127:5: note: declared here
int btrfs_create_qgroup(struct btrfs_trans_handle *trans,
^~~~~~~~~~~~~~~~~~~
fs/btrfs/tests/qgroup-tests.c: In function 'test_multiple_refs':
fs/btrfs/tests/qgroup-tests.c:334:8: error: too few arguments to function 'btrfs_create_qgroup'
ret = btrfs_create_qgroup(NULL, fs_info, BTRFS_FIRST_FREE_OBJECTID);
^~~~~~~~~~~~~~~~~~~ In file included from fs/btrfs/tests/qgroup-tests.c:24:0:
fs/btrfs/tests/../qgroup.h:127:5: note: declared here
int btrfs_create_qgroup(struct btrfs_trans_handle *trans,
^~~~~~~~~~~~~~~~~~~
vim +232 fs/btrfs/tests/qgroup-tests.c
faa2dbf0 Josef Bacik 2014-05-07 219
b9ef22de Feifei Xu 2016-06-01 220 static int test_no_shared_qgroup(struct btrfs_root *root,
b9ef22de Feifei Xu 2016-06-01 221 u32 sectorsize, u32 nodesize)
faa2dbf0 Josef Bacik 2014-05-07 222 {
faa2dbf0 Josef Bacik 2014-05-07 223 struct btrfs_trans_handle trans;
faa2dbf0 Josef Bacik 2014-05-07 224 struct btrfs_fs_info *fs_info = root->fs_info;
442244c9 Qu Wenruo 2015-04-16 225 struct ulist *old_roots = NULL;
442244c9 Qu Wenruo 2015-04-16 226 struct ulist *new_roots = NULL;
faa2dbf0 Josef Bacik 2014-05-07 227 int ret;
faa2dbf0 Josef Bacik 2014-05-07 228
7c55ee0c Omar Sandoval 2015-09-29 229 btrfs_init_dummy_trans(&trans);
faa2dbf0 Josef Bacik 2014-05-07 230
faa2dbf0 Josef Bacik 2014-05-07 231 test_msg("Qgroup basic add\n");
ef9f2db3 Feifei Xu 2016-06-01 @232 ret = btrfs_create_qgroup(NULL, fs_info, BTRFS_FS_TREE_OBJECTID);
faa2dbf0 Josef Bacik 2014-05-07 233 if (ret) {
faa2dbf0 Josef Bacik 2014-05-07 234 test_msg("Couldn't create a qgroup %d\n", ret);
faa2dbf0 Josef Bacik 2014-05-07 235 return ret;
faa2dbf0 Josef Bacik 2014-05-07 236 }
faa2dbf0 Josef Bacik 2014-05-07 237
442244c9 Qu Wenruo 2015-04-16 238 /*
01327610 Nicholas D Steeves 2016-05-19 239 * Since the test trans doesn't have the complicated delayed refs,
442244c9 Qu Wenruo 2015-04-16 240 * we can only call btrfs_qgroup_account_extent() directly to test
442244c9 Qu Wenruo 2015-04-16 241 * quota.
442244c9 Qu Wenruo 2015-04-16 242 */
b9ef22de Feifei Xu 2016-06-01 243 ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &old_roots);
faa2dbf0 Josef Bacik 2014-05-07 244 if (ret) {
442244c9 Qu Wenruo 2015-04-16 245 ulist_free(old_roots);
442244c9 Qu Wenruo 2015-04-16 246 test_msg("Couldn't find old roots: %d\n", ret);
faa2dbf0 Josef Bacik 2014-05-07 247 return ret;
faa2dbf0 Josef Bacik 2014-05-07 248 }
faa2dbf0 Josef Bacik 2014-05-07 249
ef9f2db3 Feifei Xu 2016-06-01 250 ret = insert_normal_tree_ref(root, nodesize, nodesize, 0,
ef9f2db3 Feifei Xu 2016-06-01 251 BTRFS_FS_TREE_OBJECTID);
faa2dbf0 Josef Bacik 2014-05-07 252 if (ret)
faa2dbf0 Josef Bacik 2014-05-07 253 return ret;
faa2dbf0 Josef Bacik 2014-05-07 254
b9ef22de Feifei Xu 2016-06-01 255 ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &new_roots);
442244c9 Qu Wenruo 2015-04-16 256 if (ret) {
442244c9 Qu Wenruo 2015-04-16 257 ulist_free(old_roots);
442244c9 Qu Wenruo 2015-04-16 258 ulist_free(new_roots);
442244c9 Qu Wenruo 2015-04-16 259 test_msg("Couldn't find old roots: %d\n", ret);
442244c9 Qu Wenruo 2015-04-16 260 return ret;
442244c9 Qu Wenruo 2015-04-16 261 }
442244c9 Qu Wenruo 2015-04-16 262
b9ef22de Feifei Xu 2016-06-01 263 ret = btrfs_qgroup_account_extent(&trans, fs_info, nodesize,
b9ef22de Feifei Xu 2016-06-01 264 nodesize, old_roots, new_roots);
faa2dbf0 Josef Bacik 2014-05-07 265 if (ret) {
442244c9 Qu Wenruo 2015-04-16 266 test_msg("Couldn't account space for a qgroup %d\n", ret);
faa2dbf0 Josef Bacik 2014-05-07 267 return ret;
faa2dbf0 Josef Bacik 2014-05-07 268 }
faa2dbf0 Josef Bacik 2014-05-07 269
ef9f2db3 Feifei Xu 2016-06-01 270 if (btrfs_verify_qgroup_counts(fs_info, BTRFS_FS_TREE_OBJECTID,
ef9f2db3 Feifei Xu 2016-06-01 271 nodesize, nodesize)) {
faa2dbf0 Josef Bacik 2014-05-07 272 test_msg("Qgroup counts didn't match expected values\n");
faa2dbf0 Josef Bacik 2014-05-07 273 return -EINVAL;
faa2dbf0 Josef Bacik 2014-05-07 274 }
442244c9 Qu Wenruo 2015-04-16 275 old_roots = NULL;
442244c9 Qu Wenruo 2015-04-16 276 new_roots = NULL;
442244c9 Qu Wenruo 2015-04-16 277
b9ef22de Feifei Xu 2016-06-01 278 ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &old_roots);
442244c9 Qu Wenruo 2015-04-16 279 if (ret) {
442244c9 Qu Wenruo 2015-04-16 280 ulist_free(old_roots);
442244c9 Qu Wenruo 2015-04-16 281 test_msg("Couldn't find old roots: %d\n", ret);
442244c9 Qu Wenruo 2015-04-16 282 return ret;
442244c9 Qu Wenruo 2015-04-16 283 }
faa2dbf0 Josef Bacik 2014-05-07 284
b9ef22de Feifei Xu 2016-06-01 285 ret = remove_extent_item(root, nodesize, nodesize);
faa2dbf0 Josef Bacik 2014-05-07 286 if (ret)
faa2dbf0 Josef Bacik 2014-05-07 287 return -EINVAL;
faa2dbf0 Josef Bacik 2014-05-07 288
b9ef22de Feifei Xu 2016-06-01 289 ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &new_roots);
faa2dbf0 Josef Bacik 2014-05-07 290 if (ret) {
442244c9 Qu Wenruo 2015-04-16 291 ulist_free(old_roots);
442244c9 Qu Wenruo 2015-04-16 292 ulist_free(new_roots);
442244c9 Qu Wenruo 2015-04-16 293 test_msg("Couldn't find old roots: %d\n", ret);
442244c9 Qu Wenruo 2015-04-16 294 return ret;
faa2dbf0 Josef Bacik 2014-05-07 295 }
faa2dbf0 Josef Bacik 2014-05-07 296
b9ef22de Feifei Xu 2016-06-01 297 ret = btrfs_qgroup_account_extent(&trans, fs_info, nodesize,
b9ef22de Feifei Xu 2016-06-01 298 nodesize, old_roots, new_roots);
faa2dbf0 Josef Bacik 2014-05-07 299 if (ret) {
442244c9 Qu Wenruo 2015-04-16 300 test_msg("Couldn't account space for a qgroup %d\n", ret);
faa2dbf0 Josef Bacik 2014-05-07 301 return -EINVAL;
faa2dbf0 Josef Bacik 2014-05-07 302 }
faa2dbf0 Josef Bacik 2014-05-07 303
ef9f2db3 Feifei Xu 2016-06-01 304 if (btrfs_verify_qgroup_counts(fs_info, BTRFS_FS_TREE_OBJECTID, 0, 0)) {
faa2dbf0 Josef Bacik 2014-05-07 305 test_msg("Qgroup counts didn't match expected values\n");
faa2dbf0 Josef Bacik 2014-05-07 306 return -EINVAL;
faa2dbf0 Josef Bacik 2014-05-07 307 }
faa2dbf0 Josef Bacik 2014-05-07 308
faa2dbf0 Josef Bacik 2014-05-07 309 return 0;
faa2dbf0 Josef Bacik 2014-05-07 310 }
faa2dbf0 Josef Bacik 2014-05-07 311 :::::: The code at line 232 was first introduced by commit
:::::: ef9f2db365c31433e52b0c5863793273bb632666 Btrfs: self-tests: Use macros instead of constants and add missing newline
:::::: TO: Feifei Xu <[email protected]> :::::: CC: David Sterba <[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation