Skip to contentSkip to conversation

btrfs-progs: simple quotas

PATCH In review Boris Burkov 2 participants 17 messages Jul 5, 2023 – Jul 13, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover btrfs-progs: simple quotas

btrfs-progs changes for supporting simple quotas. Notably:
btrfs quota can enable squota via ioctl
mkfs can create an fs with squota enabled btrfstune can enable squota
btrfs inspect commands dump squota fields
btrfs check validates and repairs squota invariants

Boris Burkov (8):
btrfs-progs: document squotas
btrfs-progs: simple quotas kernel definitions
btrfs-progs: simple quotas dump commands
btrfs-progs: simple quotas fsck
btrfs-progs: simple quotas mkfs
btrfs-progs: simple quotas btrfstune
btrfs-progs: simple quotas enable cmd
btrfs-progs: tree-checker: handle owner ref items

 Documentation/btrfs-quota.rst    |   7 +-
 Documentation/ch-quota-intro.rst |  59 +++++++++++
 Documentation/mkfs.btrfs.rst     |   6 ++
 Makefile                         |   2 +-
 check/main.c                     |   2 +
 check/qgroup-verify.c            | 122 ++++++++++++++++++----
 cmds/quota.c                     |  41 ++++++--
 common/fsfeatures.c              |   9 ++
 kernel-shared/accessors.h        |   9 ++
 kernel-shared/ctree.h            |   6 +-
 kernel-shared/print-tree.c       |  27 ++++-
 kernel-shared/tree-checker.c     |   2 +
 kernel-shared/uapi/btrfs.h       |   4 +
 kernel-shared/uapi/btrfs_tree.h  |  12 +++
 mkfs/main.c                      |  63 ++++++++++--
 tune/main.c                      |  13 ++-
 tune/quota.c                     | 169 +++++++++++++++++++++++++++++++
 tune/tune.h                      |   3 +
 18 files changed, 513 insertions(+), 43 deletions(-)
 create mode 100644 tune/quota.c
Signature · 1 line
2.41.0
#1 lore raw

PATCH 1/8 btrfs-progs: document squotas

Document the new options in btrfs quota and mkfs.btrfs. Also, add a section to the long form qgroups document about squotas.

---
 Documentation/btrfs-quota.rst    |  7 +++-
 Documentation/ch-quota-intro.rst | 59 ++++++++++++++++++++++++++++++++
 Documentation/mkfs.btrfs.rst     |  6 ++++
 3 files changed, 71 insertions(+), 1 deletion(-)
Documentation/btrfs-quota.rst +6 -1
index 830e9059a..d5e08330e 100644
@@ -47,9 +47,14 @@ SUBCOMMAND
 disable <path>
         Disable subvolume quota support for a filesystem.
 
-enable <path>
+enable [options] <path>
         Enable subvolume quota support for a filesystem.
 
+        ``Options``
+
+	-s|--simple
+		use simple quotas (squotas) instead of qgroups
+
 rescan [options] <path>
         Trash all qgroup numbers and scan the metadata again with the current config.
 
Documentation/ch-quota-intro.rst +59 -0

62 lines not on this page · raw message

Documentation/mkfs.btrfs.rst +6 -0
index d1626f736..051e8fb1c 100644
@@ -307,6 +307,12 @@ block-group-tree
 
         Enable the block group tree to greatly reduce mount time for large filesystems.
 
+squota
+	(kernel support since X.X)
+
+	Enable simple quota support (squotas). This is an alternative to qgroups with
+	a smaller performance impact but no notion of shared vs. exclusive usage.
+
 .. _mkfs-section-profiles:
 
 BLOCK GROUPS, CHUNKS, RAID
Signature · 1 line
2.41.0
#2 lore raw

Re: [PATCH 1/8] btrfs-progs: document squotas

Quoted 55 lines · Boris Burkov

Document the new options in btrfs quota and mkfs.btrfs. Also, add a section to the long form qgroups document about squotas.

---
 Documentation/btrfs-quota.rst    |  7 +++-
 Documentation/ch-quota-intro.rst | 59 ++++++++++++++++++++++++++++++++
 Documentation/mkfs.btrfs.rst     |  6 ++++
 3 files changed, 71 insertions(+), 1 deletion(-)
Documentation/btrfs-quota.rst +6 -1
index 830e9059a..d5e08330e 100644
@@ -47,9 +47,14 @@ SUBCOMMAND
 disable <path>
         Disable subvolume quota support for a filesystem.
 
-enable <path>
+enable [options] <path>
         Enable subvolume quota support for a filesystem.
 
+        ``Options``
+
+	-s|--simple
+		use simple quotas (squotas) instead of qgroups
+
 rescan [options] <path>
         Trash all qgroup numbers and scan the metadata again with the current config.
 
Documentation/ch-quota-intro.rst +17 -0
index 351772d10..a69e35c8a 100644
@@ -194,3 +194,62 @@ but some snapshots for backup purposes are being created by the system.  The
 user's snapshots should be accounted to the user, not the system.  The solution
 is similar to the one from section 'Accounting snapshots to the user', but do
 not assign system snapshots to user's qgroup.
+
+Simple Quotas (squotas)
+^^^^^^^^^^^^^^^^^^^^^^^
+
+As detailed in this document, qgroups can handle many complex extent sharing
+and unsharing scenarios while maintaining an accurate count of exclusive and
+shared usage. However, this flexibility comes at a cost: many of the
+computations are global, in the sense that we must count up the number of trees
+referring to an extent after its references change. This can slow down
+transaction commits and lead to unacceptable latencies, especially in cases
+where snapshots scale up.
+
+To work around this limitation of qgroups, btrfs also supports a second set of
+quota semantics: simple quotas or squotas. Squotas fully share the qgroups API
+and hierarchical model, but do not track shared vs. exclusive usage. Instead,
+they account all extents to the subvolume that first allocated it. With a bit
+of new bookkeeping, this allows all accounting decisions to be local to the

Documentation/ch-quota-intro.rst but some snapshots for backup purposes are being created by the system. The · line 223

Quoted 10 lines
Documentation/ch-quota-intro.rst +10 -0
+allocation or freeing operation that deals with the extents themselves, and
+fully avoids the complex and costly back-reference resolutions.
+
+``Example``
+
+To illustrate the difference between squotas and qgroups, consider the following
+basic example assuming a nodesize of 16KiB.
+
+1. create subvolume 256
+1. rack up 1GiB of data and metadata usage in 256

Mis-numbered. Thanks,

Josef

#3 lore raw

PATCH 2/8 btrfs-progs: simple quotas kernel definitions

In reply to Boris Burkov

Copy over structs, accessors, and constants for simple quotas

---
 kernel-shared/accessors.h       |  9 +++++++++
 kernel-shared/ctree.h           |  6 ++++--
 kernel-shared/uapi/btrfs.h      |  1 +
 kernel-shared/uapi/btrfs_tree.h | 12 ++++++++++++
 4 files changed, 26 insertions(+), 2 deletions(-)
kernel-shared/accessors.h +9 -0
index 539c20d09..ab8c2d337 100644
@@ -379,9 +379,13 @@ static inline u32 btrfs_extent_inline_ref_size(int type)
 	if (type == BTRFS_EXTENT_DATA_REF_KEY)
 		return sizeof(struct btrfs_extent_data_ref) +
 		       offsetof(struct btrfs_extent_inline_ref, offset);
+	if (type == BTRFS_EXTENT_OWNER_REF_KEY)
+		return sizeof(struct btrfs_extent_inline_ref);
 	return 0;
 }
 
+BTRFS_SETGET_FUNCS(extent_owner_ref_root_id, struct btrfs_extent_owner_ref, root_id, 64);
+
 /* struct btrfs_node */
 BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64);
 BTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64);
@@ -979,6 +983,9 @@ BTRFS_SETGET_FUNCS(qgroup_status_flags, struct btrfs_qgroup_status_item,
 		   flags, 64);
 BTRFS_SETGET_FUNCS(qgroup_status_rescan, struct btrfs_qgroup_status_item,
 		   rescan, 64);
+BTRFS_SETGET_FUNCS(qgroup_status_enable_gen, struct btrfs_qgroup_status_item,
+		   enable_gen, 64);
+
 BTRFS_SETGET_STACK_FUNCS(stack_qgroup_status_generation,
 			 struct btrfs_qgroup_status_item, generation, 64);
 BTRFS_SETGET_STACK_FUNCS(stack_qgroup_status_version,
@@ -987,6 +994,8 @@ BTRFS_SETGET_STACK_FUNCS(stack_qgroup_status_flags,
 			 struct btrfs_qgroup_status_item, flags, 64);
 BTRFS_SETGET_STACK_FUNCS(stack_qgroup_status_rescan,
 			 struct btrfs_qgroup_status_item, rescan, 64);
+BTRFS_SETGET_STACK_FUNCS(stack_qgroup_status_enable_gen,
+			 struct btrfs_qgroup_status_item, enable_gen, 64);
 
 /* btrfs_qgroup_info_item */
 BTRFS_SETGET_FUNCS(qgroup_info_generation, struct btrfs_qgroup_info_item,
kernel-shared/ctree.h +4 -2
index 5d3392ae8..3b283b21e 100644
@@ -102,7 +102,8 @@ static inline u32 __BTRFS_LEAF_DATA_SIZE(u32 nodesize)
 	 BTRFS_FEATURE_INCOMPAT_RAID1C34 |		\
 	 BTRFS_FEATURE_INCOMPAT_METADATA_UUID |		\
 	 BTRFS_FEATURE_INCOMPAT_ZONED |			\
-	 BTRFS_FEATURE_INCOMPAT_EXTENT_TREE_V2)
+	 BTRFS_FEATURE_INCOMPAT_EXTENT_TREE_V2 | \
+	 BTRFS_FEATURE_INCOMPAT_SIMPLE_QUOTA)
 #else
 #define BTRFS_FEATURE_INCOMPAT_SUPP			\
 	(BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF |		\
@@ -117,7 +118,8 @@ static inline u32 __BTRFS_LEAF_DATA_SIZE(u32 nodesize)
 	 BTRFS_FEATURE_INCOMPAT_NO_HOLES |		\
 	 BTRFS_FEATURE_INCOMPAT_RAID1C34 |		\
 	 BTRFS_FEATURE_INCOMPAT_METADATA_UUID |		\
-	 BTRFS_FEATURE_INCOMPAT_ZONED)
+	 BTRFS_FEATURE_INCOMPAT_ZONED | \
+	 BTRFS_FEATURE_INCOMPAT_SIMPLE_QUOTA)
 #endif
 
 /*
kernel-shared/uapi/btrfs.h +1 -0
index 85b04f89a..d312b9f4f 100644
@@ -356,6 +356,7 @@ _static_assert(sizeof(struct btrfs_ioctl_fs_info_args) == 1024);
 #define BTRFS_FEATURE_INCOMPAT_RAID1C34		(1ULL << 11)
 #define BTRFS_FEATURE_INCOMPAT_ZONED		(1ULL << 12)
 #define BTRFS_FEATURE_INCOMPAT_EXTENT_TREE_V2	(1ULL << 13)
+#define BTRFS_FEATURE_INCOMPAT_SIMPLE_QUOTA	(1ULL << 14)
 
 struct btrfs_ioctl_feature_flags {
 	__u64 compat_flags;
kernel-shared/uapi/btrfs_tree.h +12 -0
index ad555e705..a9fdbbb1e 100644
@@ -227,6 +227,8 @@
 
 #define BTRFS_SHARED_DATA_REF_KEY	184
 
+#define BTRFS_EXTENT_OWNER_REF_KEY	190
+
 /*
  * block groups give us hints into the extent allocation trees.  Which
  * blocks are free etc etc
@@ -783,6 +785,10 @@ struct btrfs_shared_data_ref {
 	__le32 count;
 } __attribute__ ((__packed__));
 
+struct btrfs_extent_owner_ref {
+	__le64 root_id;
+} __attribute__ ((__packed__));
+
 struct btrfs_extent_inline_ref {
 	__u8 type;
 	__le64 offset;
@@ -1224,6 +1230,12 @@ struct btrfs_qgroup_status_item {
 	 * of the scan. It contains a logical address
 	 */
 	__le64 rescan;
+
+	/*
+	 * Used by simple quotas to ignore old extent deletions
+	 * Present iff incompat flag SIMPLE_QUOTA is set
+	 */
+	__le64 enable_gen;
 } __attribute__ ((__packed__));
 
 struct btrfs_qgroup_info_item {
Signature · 1 line
2.41.0
#5 lore raw

PATCH 3/8 btrfs-progs: simple quotas dump commands

In reply to Boris Burkov

Add support to btrfs inspect-internal dump-super and dump-tree for the new structures and feature flags introduced by simple quotas

---
 kernel-shared/print-tree.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)
kernel-shared/print-tree.c +26 -1
index 0f7f7b72f..7d4e77579 100644
@@ -509,6 +509,10 @@ void print_extent_item(struct extent_buffer *eb, int slot, int metadata)
 			       (unsigned long long)offset,
 			       btrfs_shared_data_ref_count(eb, sref));
 			break;
+		case BTRFS_EXTENT_OWNER_REF_KEY:
+			printf("\t\textent owner root %llu\n",
+			       (unsigned long long)offset);
+			break;
 		default:
 			return;
 		}
@@ -661,6 +665,7 @@ void print_key_type(FILE *stream, u64 objectid, u8 type)
 		[BTRFS_EXTENT_DATA_REF_KEY]	= "EXTENT_DATA_REF",
 		[BTRFS_SHARED_DATA_REF_KEY]	= "SHARED_DATA_REF",
 		[BTRFS_EXTENT_REF_V0_KEY]	= "EXTENT_REF_V0",
+		[BTRFS_EXTENT_OWNER_REF_KEY]	= "EXTENT_OWNER_REF",
 		[BTRFS_CSUM_ITEM_KEY]		= "CSUM_ITEM",
 		[BTRFS_EXTENT_CSUM_KEY]		= "EXTENT_CSUM",
 		[BTRFS_EXTENT_DATA_KEY]		= "EXTENT_DATA",
@@ -1042,6 +1047,17 @@ static void print_shared_data_ref(struct extent_buffer *eb, int slot)
 		btrfs_shared_data_ref_count(eb, sref));
 }
 
+static void print_extent_owner_ref(struct extent_buffer *eb, int slot)
+{
+	struct btrfs_extent_owner_ref *oref;
+	u64 root_id;
+
+	oref = btrfs_item_ptr(eb, slot, struct btrfs_extent_owner_ref);
+	root_id = btrfs_extent_owner_ref_root_id(eb, oref);
+
+	printf("\t\textent owner root %llu\n", root_id);
+}
+
 static void print_free_space_info(struct extent_buffer *eb, int slot)
 {
 	struct btrfs_free_space_info *free_info;
@@ -1083,11 +1099,16 @@ static void print_qgroup_status(struct extent_buffer *eb, int slot)
 	memset(flags_str, 0, sizeof(flags_str));
 	qgroup_flags_to_str(btrfs_qgroup_status_flags(eb, qg_status),
 					flags_str);
-	printf("\t\tversion %llu generation %llu flags %s scan %llu\n",
+	printf("\t\tversion %llu generation %llu flags %s scan %llu",
 		(unsigned long long)btrfs_qgroup_status_version(eb, qg_status),
 		(unsigned long long)btrfs_qgroup_status_generation(eb, qg_status),
 		flags_str,
 		(unsigned long long)btrfs_qgroup_status_rescan(eb, qg_status));
+	if (btrfs_fs_incompat(eb->fs_info, SIMPLE_QUOTA))
+		printf(" enable_gen %llu\n",
+			   (unsigned long long)btrfs_qgroup_status_enable_gen(eb, qg_status));
+	else
+		printf("\n");
 }
 
 static void print_qgroup_info(struct extent_buffer *eb, int slot)
@@ -1407,6 +1428,9 @@ void btrfs_print_leaf(struct extent_buffer *eb, unsigned int mode)
 		case BTRFS_SHARED_DATA_REF_KEY:
 			print_shared_data_ref(eb, i);
 			break;
+		case BTRFS_EXTENT_OWNER_REF_KEY:
+			print_extent_owner_ref(eb, i);
+			break;
 		case BTRFS_EXTENT_REF_V0_KEY:
 			printf("\t\textent ref v0 (deprecated)\n");
 			break;
@@ -1708,6 +1732,7 @@ static struct readable_flag_entry incompat_flags_array[] = {
 	DEF_INCOMPAT_FLAG_ENTRY(RAID1C34),
 	DEF_INCOMPAT_FLAG_ENTRY(ZONED),
 	DEF_INCOMPAT_FLAG_ENTRY(EXTENT_TREE_V2),
+	DEF_INCOMPAT_FLAG_ENTRY(SIMPLE_QUOTA),
 };
 static const int incompat_flags_num = sizeof(incompat_flags_array) /
 				      sizeof(struct readable_flag_entry);
Signature · 1 line
2.41.0
#7 lore raw

PATCH 4/8 btrfs-progs: simple quotas fsck

In reply to Boris Burkov

Add simple quotas checks to btrfs check.

Like the kernel feature, these checks bypass most of the backref walking in the qgroups check. Instead, they enforce the invariant behind the design of simple quotas by scanning the extent tree and determining the owner of each extent:
Data: reading the owner ref inline item
Metadata: reading the tree block and reading its btrfs_header's owner

This gives us the expected count from squotas which we check against the on-disk state of the qgroup items

---
 check/main.c          |   2 +
 check/qgroup-verify.c | 122 ++++++++++++++++++++++++++++++++++--------
 2 files changed, 102 insertions(+), 22 deletions(-)
check/main.c +2 -0
index 77bb50a0e..07f31fbe0 100644
@@ -5667,6 +5667,8 @@ static int process_extent_item(struct btrfs_root *root,
 					btrfs_shared_data_ref_count(eb, sref),
 					gen, 0, num_bytes);
 			break;
+		case BTRFS_EXTENT_OWNER_REF_KEY:
+			break;
 		default:
 			fprintf(stderr,
 				"corrupt extent record: key [%llu,%u,%llu]\n",
check/qgroup-verify.c +100 -22

278 lines not on this page · raw message

Signature · 1 line
2.41.0
#8 lore raw

Re: [PATCH 4/8] btrfs-progs: simple quotas fsck

Quoted 74 lines · Boris Burkov

Add simple quotas checks to btrfs check.

Like the kernel feature, these checks bypass most of the backref walking in the qgroups check. Instead, they enforce the invariant behind the design of simple quotas by scanning the extent tree and determining the owner of each extent:
Data: reading the owner ref inline item
Metadata: reading the tree block and reading its btrfs_header's owner

This gives us the expected count from squotas which we check against the on-disk state of the qgroup items

---
 check/main.c          |   2 +
 check/qgroup-verify.c | 122 ++++++++++++++++++++++++++++++++++--------
 2 files changed, 102 insertions(+), 22 deletions(-)
check/main.c +2 -0
index 77bb50a0e..07f31fbe0 100644
@@ -5667,6 +5667,8 @@ static int process_extent_item(struct btrfs_root *root,
 					btrfs_shared_data_ref_count(eb, sref),
 					gen, 0, num_bytes);
 			break;
+		case BTRFS_EXTENT_OWNER_REF_KEY:
+			break;
 		default:
 			fprintf(stderr,
 				"corrupt extent record: key [%llu,%u,%llu]\n",
check/qgroup-verify.c +7 -5
index 1a62009b8..0d079f3b7 100644
@@ -85,6 +85,8 @@ static struct counts_tree {
 	unsigned int		num_groups;
 	unsigned int		rescan_running:1;
 	unsigned int		qgroup_inconsist:1;
+	unsigned int        simple:1;
+	u64         enable_gen;
 	u64			scan_progress;
 } counts = { .root = RB_ROOT };
 
@@ -341,14 +343,14 @@ static int find_parent_roots(struct ulist *roots, u64 parent)
 	ref = find_ref_bytenr(parent);
 	if (!ref) {
 		error("bytenr ref not found for parent %llu",
-				(unsigned long long)parent);
+		      (unsigned long long)parent);
 		return -EIO;
 	}
 	node = &ref->bytenr_node;
 	if (ref->bytenr != parent) {
 		error("found bytenr ref does not match parent: %llu != %llu",
-				(unsigned long long)ref->bytenr,
-				(unsigned long long)parent);
+		      (unsigned long long)ref->bytenr,
+		      (unsigned long long)parent);
 		return -EIO;
 	}
 
@@ -364,8 +366,8 @@ static int find_parent_roots(struct ulist *roots, u64 parent)
 			prev = rb_entry(prev_node, struct ref, bytenr_node);
 			if (prev->bytenr == parent) {
 				error(
-				"unexpected: prev bytenr same as parent: %llu",
-						(unsigned long long)parent);
+				      "unexpected: prev bytenr same as parent: %llu",
+				      (unsigned long long)parent);
 				return -EIO;
 			}
 		}

check/qgroup-verify.c static int travel_tree(struct btrfs_fs_info *info, struct btrfs_root *root, · line 722

Quoted 6 lines
check/qgroup-verify.c +0 -3
@@ -717,9 +719,6 @@ static int travel_tree(struct btrfs_fs_info *info, struct btrfs_root *root,
 	u64 new_bytenr;
 	u64 new_num_bytes;
 
-//	printf("travel_tree: bytenr: %llu\tnum_bytes: %llu\tref_parent: %llu\n",
-//	       bytenr, num_bytes, ref_parent);
-

Don't make big formatting changes with code changes, it makes it hard to tell what's important and what I can gloss over. Thanks,

Josef

#9 lore raw

PATCH 5/8 btrfs-progs: simple quotas mkfs

In reply to Boris Burkov

Add the ability to enable simple quotas from mkfs with '-O squota'

There is some complication around handling enable gen while still counting the root node of an fs. To handle this, employ a hack of doing a no-op write on the root node to bump its generation up above that of the qgroup enable generation, which results in counting it properly.

---
 common/fsfeatures.c |  9 +++++++
 mkfs/main.c         | 63 ++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 66 insertions(+), 6 deletions(-)
common/fsfeatures.c +9 -0
index 00658fa51..584ecb5fc 100644
@@ -108,6 +108,15 @@ static const struct btrfs_feature mkfs_features[] = {
 		VERSION_NULL(default),
 		.desc		= "quota support (qgroups)"
 	},
+	{
+		.name		= "squota",
+		.incompat_flag	= BTRFS_FEATURE_INCOMPAT_SIMPLE_QUOTA,
+		.sysfs_name	= "squota",
+		VERSION_TO_STRING2(compat, 6,5),
+		VERSION_NULL(safe),
+		VERSION_NULL(default),
+		.desc		= "squota support (simple qgroups)"
+	},
 	{
 		.name		= "extref",
 		.incompat_flag	= BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF,
mkfs/main.c +57 -6

103 lines not on this page · raw message

Signature · 1 line
2.41.0
Reviewed-by on v1 5/8
#10 lore raw

Re: [PATCH 5/8] btrfs-progs: simple quotas mkfs

Quoted 8 lines · Boris Burkov

Add the ability to enable simple quotas from mkfs with '-O squota'

There is some complication around handling enable gen while still counting the root node of an fs. To handle this, employ a hack of doing a no-op write on the root node to bump its generation up above that of the qgroup enable generation, which results in counting it properly.

Thanks,

Josef

#11 lore raw

PATCH 6/8 btrfs-progs: simple quotas btrfstune

In reply to Boris Burkov

Add the ability to enable simple quotas on an existing file system at rest with btrfstune.

This is similar to the functionality in mkfs, except it must also find all the roots for which it must create qgroups. Note that this *does not* retroactively compute usage for existing extents as that is impossible for data. This is consistent with the behavior of the live enable ioctl.

---
 Makefile     |   2 +-
 tune/main.c  |  13 +++-
 tune/quota.c | 169 +++++++++++++++++++++++++++++++++++++++++++++++++++
 tune/tune.h  |   3 +
 4 files changed, 184 insertions(+), 3 deletions(-)
 create mode 100644 tune/quota.c
Makefile +1 -1
index 86c73590d..74862ff32 100644
@@ -257,7 +257,7 @@ convert_objects = convert/main.o convert/common.o convert/source-fs.o \
 mkfs_objects = mkfs/main.o mkfs/common.o mkfs/rootdir.o
 image_objects = image/main.o image/sanitize.o
 tune_objects = tune/main.o tune/seeding.o tune/change-uuid.o tune/change-metadata-uuid.o \
-	       tune/convert-bgt.o tune/change-csum.o check/clear-cache.o
+	       tune/convert-bgt.o tune/change-csum.o tune/quota.o check/clear-cache.o
 all_objects = $(objects) $(cmds_objects) $(libbtrfs_objects) $(convert_objects) \
 	      $(mkfs_objects) $(image_objects) $(tune_objects) $(libbtrfsutil_objects)
 
tune/main.c +11 -2
index e38c1f6d3..b694d0da0 100644
@@ -103,6 +103,7 @@ static const char * const tune_usage[] = {
 	OPTLINE("-x", "enable skinny metadata extent refs (mkfs: skinny-metadata)"),
 	OPTLINE("-n", "enable no-holes feature (mkfs: no-holes, more efficient sparse file representation)"),
 	OPTLINE("-S <0|1>", "set/unset seeding status of a device"),
+	OPTLINE("-q", "enable simple quotas on the file system. (mkfs: squota)"),
 	OPTLINE("--convert-to-block-group-tree", "convert filesystem to track block groups in "
 			"the separate block-group-tree instead of extent tree (sets the incompat bit)"),
 	OPTLINE("--convert-from-block-group-tree",
@@ -147,6 +148,7 @@ int BOX_MAIN(btrfstune)(int argc, char *argv[])
 	char *new_fsid_str = NULL;
 	int ret;
 	u64 super_flags = 0;
+	int quota = 0;
 	int fd = -1;
 
 	btrfs_config_init();
@@ -169,7 +171,7 @@ int BOX_MAIN(btrfstune)(int argc, char *argv[])
 #endif
 			{ NULL, 0, NULL, 0 }
 		};
-		int c = getopt_long(argc, argv, "S:rxfuU:nmM:", long_options, NULL);
+		int c = getopt_long(argc, argv, "S:rxqfuU:nmM:", long_options, NULL);
 
 		if (c < 0)
 			break;
@@ -184,6 +186,9 @@ int BOX_MAIN(btrfstune)(int argc, char *argv[])
 		case 'x':
 			super_flags |= BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA;
 			break;
+		case 'q':
+			quota = 1;
+			break;
 		case 'n':
 			super_flags |= BTRFS_FEATURE_INCOMPAT_NO_HOLES;
 			break;
@@ -241,7 +246,7 @@ int BOX_MAIN(btrfstune)(int argc, char *argv[])
 	}
 	if (!super_flags && !seeding_flag && !(random_fsid || new_fsid_str) &&
 	    !change_metadata_uuid && csum_type == -1 && !to_bg_tree &&
-	    !to_extent_tree && !to_fst) {
+	    !to_extent_tree && !to_fst && !quota) {
 		error("at least one option should be specified");
 		usage(&tune_cmd, 1);
 		return 1;
@@ -420,6 +425,10 @@ int BOX_MAIN(btrfstune)(int argc, char *argv[])
 		total++;
 	}
 
+	if (quota) {
+		ret = enable_quota(root->fs_info, true);
+	}
+
 	if (success == total) {
 		ret = 0;
 	} else {
tune/quota.c new file +169 -0

169 lines not on this page · raw message

tune/tune.h +3 -0
index 0ef249d89..cbf33b2e7 100644
@@ -33,4 +33,7 @@ int convert_to_bg_tree(struct btrfs_fs_info *fs_info);
 int convert_to_extent_tree(struct btrfs_fs_info *fs_info);
 
 int btrfs_change_csum_type(struct btrfs_fs_info *fs_info, u16 new_csum_type);
+
+int enable_quota(struct btrfs_fs_info *fs_info, bool simple);
+
 #endif
Signature · 1 line
2.41.0
Reviewed-by on v1 6/8
#12 lore raw

Re: [PATCH 6/8] btrfs-progs: simple quotas btrfstune

Quoted 10 lines · Boris Burkov

Add the ability to enable simple quotas on an existing file system at rest with btrfstune.

This is similar to the functionality in mkfs, except it must also find all the roots for which it must create qgroups. Note that this *does not* retroactively compute usage for existing extents as that is impossible for data. This is consistent with the behavior of the live enable ioctl.

Thanks,

Josef

#13 lore raw

PATCH 7/8 btrfs-progs: simple quotas enable cmd

In reply to Boris Burkov

Add a --simple flag to btrfs quota enable. If set, this enables simple quotas instead of full qgroups.

This re-uses the deprecated 'status' field of the quota ioctl to avoid adding a new ioctl.

---
 cmds/quota.c               | 41 ++++++++++++++++++++++++++++++--------
 kernel-shared/uapi/btrfs.h |  3 +++
 2 files changed, 36 insertions(+), 8 deletions(-)
cmds/quota.c +33 -8
index cd874f9ed..31d36fcd8 100644
@@ -34,19 +34,17 @@ static const char * const quota_cmd_group_usage[] = {
 	NULL
 };
 
-static int quota_ctl(int cmd, int argc, char **argv)
+static int quota_ctl(int cmd, char *path, bool simple)
 {
 	int ret = 0;
 	int fd;
-	char *path = argv[1];
 	struct btrfs_ioctl_quota_ctl_args args;
 	DIR *dirstream = NULL;
 
-	if (check_argc_exact(argc, 2))
-		return -1;
-
 	memset(&args, 0, sizeof(args));
 	args.cmd = cmd;
+	if (cmd == BTRFS_QUOTA_CTL_ENABLE && simple)
+		args.status = BTRFS_QUOTA_CTL_ENABLE_SIMPLE_QUOTA;
 
 	fd = btrfs_open_dir(path, &dirstream, 1);
 	if (fd < 0)
@@ -67,16 +65,40 @@ static const char * const cmd_quota_enable_usage[] = {
 	"Any data already present on the filesystem will not count towards",
 	"the space usage numbers. It is recommended to enable quota for a",
 	"filesystem before writing any data to it.",
+	"",
+	"-s|--simple	simple qgroups account ownership by extent lifetime rather than backref walks",
 	NULL
 };
 
 static int cmd_quota_enable(const struct cmd_struct *cmd, int argc, char **argv)
 {
 	int ret;
+	bool simple = false;
 
-	clean_args_no_options(cmd, argc, argv);
+	optind = 0;
+	while (1) {
+		static const struct option long_options[] = {
+			{"simple", no_argument, NULL, 's'},
+			{NULL, 0, NULL, 0}
+		};
+		int c;
 
-	ret = quota_ctl(BTRFS_QUOTA_CTL_ENABLE, argc, argv);
+		c = getopt_long(argc, argv, "s", long_options, NULL);
+		if (c < 0)
+			break;
+
+		switch (c) {
+		case 's':
+			simple = true;
+			break;
+		default:
+			usage_unknown_option(cmd, argv);
+		}
+	}
+	if (check_argc_exact(argc - optind, 1))
+		return -1;
+
+	ret = quota_ctl(BTRFS_QUOTA_CTL_ENABLE, argv[optind], simple);
 
 	if (ret < 0)
 		usage(cmd, 1);
@@ -97,7 +119,10 @@ static int cmd_quota_disable(const struct cmd_struct *cmd,
 
 	clean_args_no_options(cmd, argc, argv);
 
-	ret = quota_ctl(BTRFS_QUOTA_CTL_DISABLE, argc, argv);
+	if (check_argc_exact(argc, 2))
+		return -1;
+
+	ret = quota_ctl(BTRFS_QUOTA_CTL_DISABLE, argv[1], false);
 
 	if (ret < 0)
 		usage(cmd, 1);
kernel-shared/uapi/btrfs.h +3 -0
index d312b9f4f..34c295fd6 100644
@@ -786,9 +786,12 @@ struct btrfs_ioctl_get_dev_stats {
 };
 _static_assert(sizeof(struct btrfs_ioctl_get_dev_stats) == 1032);
 
+/* cmd values */
 #define BTRFS_QUOTA_CTL_ENABLE	1
 #define BTRFS_QUOTA_CTL_DISABLE	2
 #define BTRFS_QUOTA_CTL_RESCAN__NOTUSED	3
+/* status values */
+#define BTRFS_QUOTA_CTL_ENABLE_SIMPLE_QUOTA (1UL)
 struct btrfs_ioctl_quota_ctl_args {
 	__u64 cmd;
 	__u64 status;
Signature · 1 line
2.41.0
#14 lore raw

Re: [PATCH 7/8] btrfs-progs: simple quotas enable cmd

Quoted 6 lines · Boris Burkov

Add a --simple flag to btrfs quota enable. If set, this enables simple quotas instead of full qgroups.

This re-uses the deprecated 'status' field of the quota ioctl to avoid adding a new ioctl.

Same comment here as the kernel review about just using cmd. Thanks,

Josef

#15 lore raw

PATCH 8/8 btrfs-progs: tree-checker: handle owner ref items

In reply to Boris Burkov

Add the new OWNER_REF inline items to the tree-checker extent item checking code. We could somehow validate the root id for being a valid fstree id, but just skipping it seems fine as well.

---
 kernel-shared/tree-checker.c | 2 ++
 1 file changed, 2 insertions(+)
kernel-shared/tree-checker.c +2 -0
index 107975891..2f834cf33 100644
@@ -1477,6 +1477,8 @@ static int check_extent_item(struct extent_buffer *leaf,
 			}
 			inline_refs += btrfs_shared_data_ref_count(leaf, sref);
 			break;
+		case BTRFS_EXTENT_OWNER_REF_KEY:
+			break;
 		default:
 			extent_err(leaf, slot, "unknown inline ref type: %u",
 				   inline_type);
Signature · 1 line
2.41.0
Reviewed-by on v1 8/8
#16 lore raw

Re: [PATCH 8/8] btrfs-progs: tree-checker: handle owner ref items

Quoted 5 lines · Boris Burkov

Add the new OWNER_REF inline items to the tree-checker extent item checking code. We could somehow validate the root id for being a valid fstree id, but just skipping it seems fine as well.

Thanks,

Josef