borisb / rpms / btrfs-progs

Forked from rpms/btrfs-progs 2 years ago
Clone
dbfe2d
From 5a5f05ff7d8b3dec2da3495530b1653d25b6a175 Mon Sep 17 00:00:00 2001
bf37f9
From: Omar Sandoval <osandov@fb.com>
bf37f9
Date: Tue, 10 Aug 2021 23:24:38 +0200
bf37f9
Subject: [PATCH] Require --clowntown for quota enable
bf37f9
bf37f9
---
bf37f9
 cmds/quota.c | 35 ++++++++++++++++++++++++++++++-----
bf37f9
 1 file changed, 30 insertions(+), 5 deletions(-)
bf37f9
bf37f9
diff --git a/cmds/quota.c b/cmds/quota.c
bf37f9
index 246dd277..07380726 100644
bf37f9
--- a/cmds/quota.c
bf37f9
+++ b/cmds/quota.c
bf37f9
@@ -16,6 +16,7 @@
bf37f9
  * Boston, MA 021110-1307, USA.
bf37f9
  */
bf37f9
 
bf37f9
+#include <getopt.h>
bf37f9
 #include <sys/ioctl.h>
bf37f9
 #include <unistd.h>
bf37f9
 
bf37f9
@@ -36,11 +37,11 @@ static int quota_ctl(int cmd, int argc, char **argv)
bf37f9
 {
bf37f9
 	int ret = 0;
bf37f9
 	int fd;
bf37f9
-	char *path = argv[1];
bf37f9
+	char *path = argv[optind];
bf37f9
 	struct btrfs_ioctl_quota_ctl_args args;
bf37f9
 	DIR *dirstream = NULL;
bf37f9
 
bf37f9
-	if (check_argc_exact(argc, 2))
bf37f9
+	if (check_argc_exact(argc - optind, 1))
bf37f9
 		return -1;
bf37f9
 
bf37f9
 	memset(&args, 0, sizeof(args));
bf37f9
@@ -60,8 +61,11 @@ static int quota_ctl(int cmd, int argc, char **argv)
bf37f9
 }
bf37f9
 
bf37f9
 static const char * const cmd_quota_enable_usage[] = {
bf37f9
-	"btrfs quota enable <path>",
bf37f9
+	"btrfs quota enable --clowntown <path>",
bf37f9
 	"Enable subvolume quota support for a filesystem.",
bf37f9
+	"FB-ONLY: Btrfs quotas are not supported at Facebook, so you must use",
bf37f9
+	"the --clowntown flag to enable quotas.",
bf37f9
+	"",
bf37f9
 	"Any data already present on the filesystem will not count towards",
bf37f9
 	"the space usage numbers. It is recommended to enable quota for a",
bf37f9
 	"filesystem before writing any data to it.",
bf37f9
@@ -71,10 +75,31 @@ static const char * const cmd_quota_enable_usage[] = {
bf37f9
 static int cmd_quota_enable(const struct cmd_struct *cmd, int argc, char **argv)
bf37f9
 {
bf37f9
 	int ret;
bf37f9
+	bool clowntown = false;
bf37f9
 
bf37f9
-	clean_args_no_options(cmd, argc, argv);
bf37f9
+	optind = 0;
bf37f9
+	while (1) {
bf37f9
+		int c;
bf37f9
+		static const struct option long_options[] = {
bf37f9
+			{ "clowntown", no_argument, NULL, 'c'},
bf37f9
+			{ NULL, 0, NULL, 0 }
bf37f9
+		};
bf37f9
+		c = getopt_long(argc, argv, "", long_options, NULL);
bf37f9
+		if (c < 0)
bf37f9
+			break;
bf37f9
+		switch (c) {
bf37f9
+		case 'c':
bf37f9
+			clowntown = true;
bf37f9
+			break;
bf37f9
+		default:
bf37f9
+			usage(cmd);
bf37f9
+		}
bf37f9
+	}
bf37f9
 
bf37f9
-	ret = quota_ctl(BTRFS_QUOTA_CTL_ENABLE, argc, argv);
bf37f9
+	if (clowntown)
bf37f9
+		ret = quota_ctl(BTRFS_QUOTA_CTL_ENABLE, argc, argv);
bf37f9
+	else
bf37f9
+		ret = -1;
bf37f9
 
bf37f9
 	if (ret < 0)
bf37f9
 		usage(cmd);
bf37f9
-- 
dbfe2d
2.35.1
bf37f9