borisb / rpms / btrfs-progs

Forked from rpms/btrfs-progs 2 years ago
Clone
Blob Blame History Raw
From 5a5f05ff7d8b3dec2da3495530b1653d25b6a175 Mon Sep 17 00:00:00 2001
From: Omar Sandoval <osandov@fb.com>
Date: Tue, 10 Aug 2021 23:24:38 +0200
Subject: [PATCH] Require --clowntown for quota enable

---
 cmds/quota.c | 35 ++++++++++++++++++++++++++++++-----
 1 file changed, 30 insertions(+), 5 deletions(-)

diff --git a/cmds/quota.c b/cmds/quota.c
index 246dd277..07380726 100644
--- a/cmds/quota.c
+++ b/cmds/quota.c
@@ -16,6 +16,7 @@
  * Boston, MA 021110-1307, USA.
  */
 
+#include <getopt.h>
 #include <sys/ioctl.h>
 #include <unistd.h>
 
@@ -36,11 +37,11 @@ static int quota_ctl(int cmd, int argc, char **argv)
 {
 	int ret = 0;
 	int fd;
-	char *path = argv[1];
+	char *path = argv[optind];
 	struct btrfs_ioctl_quota_ctl_args args;
 	DIR *dirstream = NULL;
 
-	if (check_argc_exact(argc, 2))
+	if (check_argc_exact(argc - optind, 1))
 		return -1;
 
 	memset(&args, 0, sizeof(args));
@@ -60,8 +61,11 @@ static int quota_ctl(int cmd, int argc, char **argv)
 }
 
 static const char * const cmd_quota_enable_usage[] = {
-	"btrfs quota enable <path>",
+	"btrfs quota enable --clowntown <path>",
 	"Enable subvolume quota support for a filesystem.",
+	"FB-ONLY: Btrfs quotas are not supported at Facebook, so you must use",
+	"the --clowntown flag to enable quotas.",
+	"",
 	"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.",
@@ -71,10 +75,31 @@ static const char * const cmd_quota_enable_usage[] = {
 static int cmd_quota_enable(const struct cmd_struct *cmd, int argc, char **argv)
 {
 	int ret;
+	bool clowntown = false;
 
-	clean_args_no_options(cmd, argc, argv);
+	optind = 0;
+	while (1) {
+		int c;
+		static const struct option long_options[] = {
+			{ "clowntown", no_argument, NULL, 'c'},
+			{ NULL, 0, NULL, 0 }
+		};
+		c = getopt_long(argc, argv, "", long_options, NULL);
+		if (c < 0)
+			break;
+		switch (c) {
+		case 'c':
+			clowntown = true;
+			break;
+		default:
+			usage(cmd);
+		}
+	}
 
-	ret = quota_ctl(BTRFS_QUOTA_CTL_ENABLE, argc, argv);
+	if (clowntown)
+		ret = quota_ctl(BTRFS_QUOTA_CTL_ENABLE, argc, argv);
+	else
+		ret = -1;
 
 	if (ret < 0)
 		usage(cmd);
-- 
2.35.1