@@ -34,9 +34,21 @@ enum btrfs_qgroup_mode btrfs_qgroup_mode(struct btrfs_fs_info *fs_info)
34
34
{
35
35
if (!test_bit (BTRFS_FS_QUOTA_ENABLED , & fs_info -> flags ))
36
36
return BTRFS_QGROUP_MODE_DISABLED ;
37
+ if (fs_info -> qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_SIMPLE_MODE )
38
+ return BTRFS_QGROUP_MODE_SIMPLE ;
37
39
return BTRFS_QGROUP_MODE_FULL ;
38
40
}
39
41
42
+ bool btrfs_qgroup_enabled (struct btrfs_fs_info * fs_info )
43
+ {
44
+ return btrfs_qgroup_mode (fs_info ) != BTRFS_QGROUP_MODE_DISABLED ;
45
+ }
46
+
47
+ bool btrfs_qgroup_full_accounting (struct btrfs_fs_info * fs_info )
48
+ {
49
+ return btrfs_qgroup_mode (fs_info ) == BTRFS_QGROUP_MODE_FULL ;
50
+ }
51
+
40
52
/*
41
53
* Helpers to access qgroup reservation
42
54
*
@@ -350,6 +362,8 @@ int btrfs_verify_qgroup_counts(struct btrfs_fs_info *fs_info, u64 qgroupid,
350
362
351
363
static void qgroup_mark_inconsistent (struct btrfs_fs_info * fs_info )
352
364
{
365
+ if (btrfs_qgroup_mode (fs_info ) == BTRFS_QGROUP_MODE_SIMPLE )
366
+ return ;
353
367
fs_info -> qgroup_flags |= (BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT |
354
368
BTRFS_QGROUP_RUNTIME_FLAG_CANCEL_RESCAN |
355
369
BTRFS_QGROUP_RUNTIME_FLAG_NO_ACCOUNTING );
@@ -370,8 +384,9 @@ int btrfs_read_qgroup_config(struct btrfs_fs_info *fs_info)
370
384
int ret = 0 ;
371
385
u64 flags = 0 ;
372
386
u64 rescan_progress = 0 ;
387
+ bool simple ;
373
388
374
- if (! test_bit ( BTRFS_FS_QUOTA_ENABLED , & fs_info -> flags ) )
389
+ if (btrfs_qgroup_mode ( fs_info ) == BTRFS_QGROUP_MODE_DISABLED )
375
390
return 0 ;
376
391
377
392
fs_info -> qgroup_ulist = ulist_alloc (GFP_KERNEL );
@@ -421,14 +436,14 @@ int btrfs_read_qgroup_config(struct btrfs_fs_info *fs_info)
421
436
"old qgroup version, quota disabled" );
422
437
goto out ;
423
438
}
439
+ fs_info -> qgroup_flags = btrfs_qgroup_status_flags (l , ptr );
440
+ simple = (fs_info -> qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_SIMPLE_MODE );
424
441
if (btrfs_qgroup_status_generation (l , ptr ) !=
425
- fs_info -> generation ) {
442
+ fs_info -> generation && ! simple ) {
426
443
qgroup_mark_inconsistent (fs_info );
427
444
btrfs_err (fs_info ,
428
445
"qgroup generation mismatch, marked as inconsistent" );
429
446
}
430
- fs_info -> qgroup_flags = btrfs_qgroup_status_flags (l ,
431
- ptr );
432
447
rescan_progress = btrfs_qgroup_status_rescan (l , ptr );
433
448
goto next1 ;
434
449
}
@@ -571,7 +586,7 @@ bool btrfs_check_quota_leak(struct btrfs_fs_info *fs_info)
571
586
struct rb_node * node ;
572
587
bool ret = false;
573
588
574
- if (! test_bit ( BTRFS_FS_QUOTA_ENABLED , & fs_info -> flags ) )
589
+ if (btrfs_qgroup_mode ( fs_info ) == BTRFS_QGROUP_MODE_DISABLED )
575
590
return ret ;
576
591
/*
577
592
* Since we're unmounting, there is no race and no need to grab qgroup
@@ -970,7 +985,8 @@ static int btrfs_clean_quota_tree(struct btrfs_trans_handle *trans,
970
985
return ret ;
971
986
}
972
987
973
- int btrfs_quota_enable (struct btrfs_fs_info * fs_info )
988
+ int btrfs_quota_enable (struct btrfs_fs_info * fs_info ,
989
+ struct btrfs_ioctl_quota_ctl_args * quota_ctl_args )
974
990
{
975
991
struct btrfs_root * quota_root ;
976
992
struct btrfs_root * tree_root = fs_info -> tree_root ;
@@ -983,6 +999,7 @@ int btrfs_quota_enable(struct btrfs_fs_info *fs_info)
983
999
struct btrfs_qgroup * prealloc = NULL ;
984
1000
struct btrfs_trans_handle * trans = NULL ;
985
1001
struct ulist * ulist = NULL ;
1002
+ const bool simple = (quota_ctl_args -> cmd == BTRFS_QUOTA_CTL_ENABLE_SIMPLE_QUOTA );
986
1003
int ret = 0 ;
987
1004
int slot ;
988
1005
@@ -1085,8 +1102,11 @@ int btrfs_quota_enable(struct btrfs_fs_info *fs_info)
1085
1102
struct btrfs_qgroup_status_item );
1086
1103
btrfs_set_qgroup_status_generation (leaf , ptr , trans -> transid );
1087
1104
btrfs_set_qgroup_status_version (leaf , ptr , BTRFS_QGROUP_STATUS_VERSION );
1088
- fs_info -> qgroup_flags = BTRFS_QGROUP_STATUS_FLAG_ON |
1089
- BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT ;
1105
+ fs_info -> qgroup_flags = BTRFS_QGROUP_STATUS_FLAG_ON ;
1106
+ if (simple )
1107
+ fs_info -> qgroup_flags |= BTRFS_QGROUP_STATUS_FLAG_SIMPLE_MODE ;
1108
+ else
1109
+ fs_info -> qgroup_flags |= BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT ;
1090
1110
btrfs_set_qgroup_status_flags (leaf , ptr , fs_info -> qgroup_flags &
1091
1111
BTRFS_QGROUP_STATUS_FLAGS_MASK );
1092
1112
btrfs_set_qgroup_status_rescan (leaf , ptr , 0 );
@@ -1214,8 +1234,14 @@ int btrfs_quota_enable(struct btrfs_fs_info *fs_info)
1214
1234
spin_lock (& fs_info -> qgroup_lock );
1215
1235
fs_info -> quota_root = quota_root ;
1216
1236
set_bit (BTRFS_FS_QUOTA_ENABLED , & fs_info -> flags );
1237
+ if (simple )
1238
+ btrfs_set_fs_incompat (fs_info , SIMPLE_QUOTA );
1217
1239
spin_unlock (& fs_info -> qgroup_lock );
1218
1240
1241
+ /* Skip rescan for simple qgroups. */
1242
+ if (btrfs_qgroup_mode (fs_info ) == BTRFS_QGROUP_MODE_SIMPLE )
1243
+ goto out_free_path ;
1244
+
1219
1245
ret = qgroup_rescan_init (fs_info , 0 , 1 );
1220
1246
if (!ret ) {
1221
1247
qgroup_rescan_zero_tracking (fs_info );
@@ -1330,6 +1356,7 @@ int btrfs_quota_disable(struct btrfs_fs_info *fs_info)
1330
1356
quota_root = fs_info -> quota_root ;
1331
1357
fs_info -> quota_root = NULL ;
1332
1358
fs_info -> qgroup_flags &= ~BTRFS_QGROUP_STATUS_FLAG_ON ;
1359
+ fs_info -> qgroup_flags &= ~BTRFS_QGROUP_STATUS_FLAG_SIMPLE_MODE ;
1333
1360
fs_info -> qgroup_drop_subtree_thres = BTRFS_MAX_LEVEL ;
1334
1361
spin_unlock (& fs_info -> qgroup_lock );
1335
1362
@@ -1810,6 +1837,9 @@ int btrfs_qgroup_trace_extent_nolock(struct btrfs_fs_info *fs_info,
1810
1837
struct btrfs_qgroup_extent_record * entry ;
1811
1838
u64 bytenr = record -> bytenr ;
1812
1839
1840
+ if (!btrfs_qgroup_full_accounting (fs_info ))
1841
+ return 0 ;
1842
+
1813
1843
lockdep_assert_held (& delayed_refs -> lock );
1814
1844
trace_btrfs_qgroup_trace_extent (fs_info , record );
1815
1845
@@ -1863,6 +1893,8 @@ int btrfs_qgroup_trace_extent_post(struct btrfs_trans_handle *trans,
1863
1893
struct btrfs_backref_walk_ctx ctx = { 0 };
1864
1894
int ret ;
1865
1895
1896
+ if (!btrfs_qgroup_full_accounting (trans -> fs_info ))
1897
+ return 0 ;
1866
1898
/*
1867
1899
* We are always called in a context where we are already holding a
1868
1900
* transaction handle. Often we are called when adding a data delayed
@@ -1931,8 +1963,7 @@ int btrfs_qgroup_trace_extent(struct btrfs_trans_handle *trans, u64 bytenr,
1931
1963
struct btrfs_delayed_ref_root * delayed_refs ;
1932
1964
int ret ;
1933
1965
1934
- if (!test_bit (BTRFS_FS_QUOTA_ENABLED , & fs_info -> flags )
1935
- || bytenr == 0 || num_bytes == 0 )
1966
+ if (!btrfs_qgroup_full_accounting (fs_info ) || bytenr == 0 || num_bytes == 0 )
1936
1967
return 0 ;
1937
1968
record = kzalloc (sizeof (* record ), GFP_NOFS );
1938
1969
if (!record )
@@ -1970,7 +2001,7 @@ int btrfs_qgroup_trace_leaf_items(struct btrfs_trans_handle *trans,
1970
2001
u64 bytenr , num_bytes ;
1971
2002
1972
2003
/* We can be called directly from walk_up_proc() */
1973
- if (!test_bit ( BTRFS_FS_QUOTA_ENABLED , & fs_info -> flags ))
2004
+ if (!btrfs_qgroup_full_accounting ( fs_info ))
1974
2005
return 0 ;
1975
2006
1976
2007
for (i = 0 ; i < nr ; i ++ ) {
@@ -2346,7 +2377,7 @@ static int qgroup_trace_subtree_swap(struct btrfs_trans_handle *trans,
2346
2377
int level ;
2347
2378
int ret ;
2348
2379
2349
- if (!test_bit ( BTRFS_FS_QUOTA_ENABLED , & fs_info -> flags ))
2380
+ if (!btrfs_qgroup_full_accounting ( fs_info ))
2350
2381
return 0 ;
2351
2382
2352
2383
/* Wrong parameter order */
@@ -2413,7 +2444,7 @@ int btrfs_qgroup_trace_subtree(struct btrfs_trans_handle *trans,
2413
2444
BUG_ON (root_level < 0 || root_level >= BTRFS_MAX_LEVEL );
2414
2445
BUG_ON (root_eb == NULL );
2415
2446
2416
- if (!test_bit ( BTRFS_FS_QUOTA_ENABLED , & fs_info -> flags ))
2447
+ if (!btrfs_qgroup_full_accounting ( fs_info ))
2417
2448
return 0 ;
2418
2449
2419
2450
spin_lock (& fs_info -> qgroup_lock );
@@ -2747,7 +2778,7 @@ int btrfs_qgroup_account_extent(struct btrfs_trans_handle *trans, u64 bytenr,
2747
2778
* If quotas get disabled meanwhile, the resources need to be freed and
2748
2779
* we can't just exit here.
2749
2780
*/
2750
- if (!test_bit ( BTRFS_FS_QUOTA_ENABLED , & fs_info -> flags ) ||
2781
+ if (!btrfs_qgroup_full_accounting ( fs_info ) ||
2751
2782
fs_info -> qgroup_flags & BTRFS_QGROUP_RUNTIME_FLAG_NO_ACCOUNTING )
2752
2783
goto out_free ;
2753
2784
@@ -2816,6 +2847,9 @@ int btrfs_qgroup_account_extents(struct btrfs_trans_handle *trans)
2816
2847
u64 qgroup_to_skip ;
2817
2848
int ret = 0 ;
2818
2849
2850
+ if (btrfs_qgroup_mode (fs_info ) == BTRFS_QGROUP_MODE_SIMPLE )
2851
+ return 0 ;
2852
+
2819
2853
delayed_refs = & trans -> transaction -> delayed_refs ;
2820
2854
qgroup_to_skip = delayed_refs -> qgroup_to_skip ;
2821
2855
while ((node = rb_first (& delayed_refs -> dirty_extent_root ))) {
@@ -2931,7 +2965,7 @@ int btrfs_run_qgroups(struct btrfs_trans_handle *trans)
2931
2965
qgroup_mark_inconsistent (fs_info );
2932
2966
spin_lock (& fs_info -> qgroup_lock );
2933
2967
}
2934
- if (test_bit ( BTRFS_FS_QUOTA_ENABLED , & fs_info -> flags ))
2968
+ if (btrfs_qgroup_enabled ( fs_info ))
2935
2969
fs_info -> qgroup_flags |= BTRFS_QGROUP_STATUS_FLAG_ON ;
2936
2970
else
2937
2971
fs_info -> qgroup_flags &= ~BTRFS_QGROUP_STATUS_FLAG_ON ;
@@ -2990,7 +3024,7 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,
2990
3024
2991
3025
if (!committing )
2992
3026
mutex_lock (& fs_info -> qgroup_ioctl_lock );
2993
- if (!test_bit ( BTRFS_FS_QUOTA_ENABLED , & fs_info -> flags ))
3027
+ if (!btrfs_qgroup_enabled ( fs_info ))
2994
3028
goto out ;
2995
3029
2996
3030
quota_root = fs_info -> quota_root ;
@@ -3076,7 +3110,7 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,
3076
3110
qgroup_dirty (fs_info , dstgroup );
3077
3111
}
3078
3112
3079
- if (srcid ) {
3113
+ if (srcid && btrfs_qgroup_mode ( fs_info ) == BTRFS_QGROUP_MODE_FULL ) {
3080
3114
srcgroup = find_qgroup_rb (fs_info , srcid );
3081
3115
if (!srcgroup )
3082
3116
goto unlock ;
@@ -3339,6 +3373,9 @@ static int qgroup_rescan_leaf(struct btrfs_trans_handle *trans,
3339
3373
int slot ;
3340
3374
int ret ;
3341
3375
3376
+ if (!btrfs_qgroup_full_accounting (fs_info ))
3377
+ return 1 ;
3378
+
3342
3379
mutex_lock (& fs_info -> qgroup_rescan_lock );
3343
3380
extent_root = btrfs_extent_root (fs_info ,
3344
3381
fs_info -> qgroup_rescan_progress .objectid );
@@ -3419,10 +3456,15 @@ static int qgroup_rescan_leaf(struct btrfs_trans_handle *trans,
3419
3456
3420
3457
static bool rescan_should_stop (struct btrfs_fs_info * fs_info )
3421
3458
{
3422
- return btrfs_fs_closing (fs_info ) ||
3423
- test_bit (BTRFS_FS_STATE_REMOUNTING , & fs_info -> fs_state ) ||
3424
- !test_bit (BTRFS_FS_QUOTA_ENABLED , & fs_info -> flags ) ||
3425
- fs_info -> qgroup_flags & BTRFS_QGROUP_RUNTIME_FLAG_CANCEL_RESCAN ;
3459
+ if (btrfs_fs_closing (fs_info ))
3460
+ return true;
3461
+ if (test_bit (BTRFS_FS_STATE_REMOUNTING , & fs_info -> fs_state ))
3462
+ return true;
3463
+ if (!btrfs_qgroup_enabled (fs_info ))
3464
+ return true;
3465
+ if (fs_info -> qgroup_flags & BTRFS_QGROUP_RUNTIME_FLAG_CANCEL_RESCAN )
3466
+ return true;
3467
+ return false;
3426
3468
}
3427
3469
3428
3470
static void btrfs_qgroup_rescan_worker (struct btrfs_work * work )
@@ -3436,6 +3478,9 @@ static void btrfs_qgroup_rescan_worker(struct btrfs_work *work)
3436
3478
bool stopped = false;
3437
3479
bool did_leaf_rescans = false;
3438
3480
3481
+ if (btrfs_qgroup_mode (fs_info ) == BTRFS_QGROUP_MODE_SIMPLE )
3482
+ return ;
3483
+
3439
3484
path = btrfs_alloc_path ();
3440
3485
if (!path )
3441
3486
goto out ;
@@ -3539,6 +3584,11 @@ qgroup_rescan_init(struct btrfs_fs_info *fs_info, u64 progress_objectid,
3539
3584
{
3540
3585
int ret = 0 ;
3541
3586
3587
+ if (btrfs_qgroup_mode (fs_info ) == BTRFS_QGROUP_MODE_SIMPLE ) {
3588
+ btrfs_warn (fs_info , "qgroup rescan init failed, running in simple mode" );
3589
+ return - EINVAL ;
3590
+ }
3591
+
3542
3592
if (!init_flags ) {
3543
3593
/* we're resuming qgroup rescan at mount time */
3544
3594
if (!(fs_info -> qgroup_flags &
@@ -3569,7 +3619,7 @@ qgroup_rescan_init(struct btrfs_fs_info *fs_info, u64 progress_objectid,
3569
3619
btrfs_warn (fs_info ,
3570
3620
"qgroup rescan init failed, qgroup is not enabled" );
3571
3621
ret = - EINVAL ;
3572
- } else if (! test_bit ( BTRFS_FS_QUOTA_ENABLED , & fs_info -> flags ) ) {
3622
+ } else if (btrfs_qgroup_mode ( fs_info ) == BTRFS_QGROUP_MODE_DISABLED ) {
3573
3623
/* Quota disable is in progress */
3574
3624
ret = - EBUSY ;
3575
3625
}
@@ -3828,7 +3878,7 @@ static int qgroup_reserve_data(struct btrfs_inode *inode,
3828
3878
u64 to_reserve ;
3829
3879
int ret ;
3830
3880
3831
- if (! test_bit ( BTRFS_FS_QUOTA_ENABLED , & root -> fs_info -> flags ) ||
3881
+ if (btrfs_qgroup_mode ( root -> fs_info ) == BTRFS_QGROUP_MODE_DISABLED ||
3832
3882
!is_fstree (root -> root_key .objectid ) || len == 0 )
3833
3883
return 0 ;
3834
3884
@@ -3960,7 +4010,7 @@ static int __btrfs_qgroup_release_data(struct btrfs_inode *inode,
3960
4010
int trace_op = QGROUP_RELEASE ;
3961
4011
int ret ;
3962
4012
3963
- if (! test_bit ( BTRFS_FS_QUOTA_ENABLED , & inode -> root -> fs_info -> flags ) )
4013
+ if (btrfs_qgroup_mode ( inode -> root -> fs_info ) == BTRFS_QGROUP_MODE_DISABLED )
3964
4014
return 0 ;
3965
4015
3966
4016
/* In release case, we shouldn't have @reserved */
@@ -4071,7 +4121,7 @@ int btrfs_qgroup_reserve_meta(struct btrfs_root *root, int num_bytes,
4071
4121
struct btrfs_fs_info * fs_info = root -> fs_info ;
4072
4122
int ret ;
4073
4123
4074
- if (! test_bit ( BTRFS_FS_QUOTA_ENABLED , & fs_info -> flags ) ||
4124
+ if (btrfs_qgroup_mode ( fs_info ) == BTRFS_QGROUP_MODE_DISABLED ||
4075
4125
!is_fstree (root -> root_key .objectid ) || num_bytes == 0 )
4076
4126
return 0 ;
4077
4127
@@ -4116,7 +4166,7 @@ void btrfs_qgroup_free_meta_all_pertrans(struct btrfs_root *root)
4116
4166
{
4117
4167
struct btrfs_fs_info * fs_info = root -> fs_info ;
4118
4168
4119
- if (! test_bit ( BTRFS_FS_QUOTA_ENABLED , & fs_info -> flags ) ||
4169
+ if (btrfs_qgroup_mode ( fs_info ) == BTRFS_QGROUP_MODE_DISABLED ||
4120
4170
!is_fstree (root -> root_key .objectid ))
4121
4171
return ;
4122
4172
@@ -4132,7 +4182,7 @@ void __btrfs_qgroup_free_meta(struct btrfs_root *root, int num_bytes,
4132
4182
{
4133
4183
struct btrfs_fs_info * fs_info = root -> fs_info ;
4134
4184
4135
- if (! test_bit ( BTRFS_FS_QUOTA_ENABLED , & fs_info -> flags ) ||
4185
+ if (btrfs_qgroup_mode ( fs_info ) == BTRFS_QGROUP_MODE_DISABLED ||
4136
4186
!is_fstree (root -> root_key .objectid ))
4137
4187
return ;
4138
4188
@@ -4191,7 +4241,7 @@ void btrfs_qgroup_convert_reserved_meta(struct btrfs_root *root, int num_bytes)
4191
4241
{
4192
4242
struct btrfs_fs_info * fs_info = root -> fs_info ;
4193
4243
4194
- if (! test_bit ( BTRFS_FS_QUOTA_ENABLED , & fs_info -> flags ) ||
4244
+ if (btrfs_qgroup_mode ( fs_info ) == BTRFS_QGROUP_MODE_DISABLED ||
4195
4245
!is_fstree (root -> root_key .objectid ))
4196
4246
return ;
4197
4247
/* Same as btrfs_qgroup_free_meta_prealloc() */
@@ -4299,7 +4349,7 @@ int btrfs_qgroup_add_swapped_blocks(struct btrfs_trans_handle *trans,
4299
4349
int level = btrfs_header_level (subvol_parent ) - 1 ;
4300
4350
int ret = 0 ;
4301
4351
4302
- if (!test_bit ( BTRFS_FS_QUOTA_ENABLED , & fs_info -> flags ))
4352
+ if (!btrfs_qgroup_full_accounting ( fs_info ))
4303
4353
return 0 ;
4304
4354
4305
4355
if (btrfs_node_ptr_generation (subvol_parent , subvol_slot ) >
@@ -4409,7 +4459,7 @@ int btrfs_qgroup_trace_subtree_after_cow(struct btrfs_trans_handle *trans,
4409
4459
int ret = 0 ;
4410
4460
int i ;
4411
4461
4412
- if (!test_bit ( BTRFS_FS_QUOTA_ENABLED , & fs_info -> flags ))
4462
+ if (!btrfs_qgroup_full_accounting ( fs_info ))
4413
4463
return 0 ;
4414
4464
if (!is_fstree (root -> root_key .objectid ) || !root -> reloc_root )
4415
4465
return 0 ;
0 commit comments