linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Disseldorp <ddiss@suse.de>
To: linux-btrfs@vger.kernel.org
Cc: David Disseldorp <ddiss@suse.de>
Subject: [PATCH 1/1] btrfs-progs: btrfstune: print seeding status
Date: Fri,  4 Jan 2019 00:22:39 +0100	[thread overview]
Message-ID: <20190103232239.11931-2-ddiss@suse.de> (raw)
In-Reply-To: <20190103232239.11931-1-ddiss@suse.de>

btrfstune -s <dev> prints "Seeding flag is currently [un]set", based on
whether or not BTRFS_SUPER_FLAG_SEEDING is enabled for the given device.

Signed-off-by: David Disseldorp <ddiss@suse.de>
---
 Documentation/btrfstune.asciidoc |  3 +++
 btrfstune.c                      | 29 +++++++++++++++++++++++++++--
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/Documentation/btrfstune.asciidoc b/Documentation/btrfstune.asciidoc
index 27100964..992da95d 100644
--- a/Documentation/btrfstune.asciidoc
+++ b/Documentation/btrfstune.asciidoc
@@ -30,6 +30,9 @@ Enable seeding on a given device. Value 1 will enable seeding, 0 will disable it
 A seeding filesystem is forced to be mounted read-only. A new device can be added
 to the filesystem and will capture all writes keeping the seeding device intact.
 
+-s::
+Print whether or not seeding is enabled for a given device.
+
 -r::
 (since kernel: 3.7)
 +
diff --git a/btrfstune.c b/btrfstune.c
index 1e378ba1..603242b7 100644
--- a/btrfstune.c
+++ b/btrfstune.c
@@ -73,6 +73,15 @@ static int update_seeding_flag(struct btrfs_root *root, int set_flag)
 	return ret;
 }
 
+static void check_seeding_flag(struct btrfs_root *root)
+{
+	struct btrfs_super_block *disk_super = root->fs_info->super_copy;
+	u64 super_flags = btrfs_super_flags(disk_super);
+
+	printf("Seeding flag is currently %sset\n",
+	       (super_flags & BTRFS_SUPER_FLAG_SEEDING ? "" : "un"));
+}
+
 static int set_super_incompat_flags(struct btrfs_root *root, u64 flags)
 {
 	struct btrfs_trans_handle *trans;
@@ -374,6 +383,7 @@ static void print_usage(void)
 {
 	printf("usage: btrfstune [options] device\n");
 	printf("\t-S value\tpositive value will enable seeding, zero to disable, negative is not allowed\n");
+	printf("\t-s \t\tcheck whether seeding is enabled\n");
 	printf("\t-r \t\tenable extended inode refs\n");
 	printf("\t-x \t\tenable skinny metadata extent refs\n");
 	printf("\t-n \t\tenable no-holes feature (more efficient sparse file representation)\n");
@@ -390,6 +400,7 @@ int main(int argc, char *argv[])
 	int total = 0;
 	int seeding_flag = 0;
 	u64 seeding_value = 0;
+	int check_seeding = 0;
 	int random_fsid = 0;
 	char *new_fsid_str = NULL;
 	int ret;
@@ -401,7 +412,7 @@ int main(int argc, char *argv[])
 			{ "help", no_argument, NULL, GETOPT_VAL_HELP},
 			{ NULL, 0, NULL, 0 }
 		};
-		int c = getopt_long(argc, argv, "S:rxfuU:n", long_options, NULL);
+		int c = getopt_long(argc, argv, "S:srxfuU:n", long_options, NULL);
 
 		if (c < 0)
 			break;
@@ -410,6 +421,9 @@ int main(int argc, char *argv[])
 			seeding_flag = 1;
 			seeding_value = arg_strtou64(optarg);
 			break;
+		case 's':
+			check_seeding = 1;
+			break;
 		case 'r':
 			super_flags |= BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF;
 			break;
@@ -448,7 +462,12 @@ int main(int argc, char *argv[])
 		error("random fsid can't be used with specified fsid");
 		return 1;
 	}
-	if (!super_flags && !seeding_flag && !(random_fsid || new_fsid_str)) {
+	if (seeding_flag && check_seeding) {
+		error("check seeding can't be used alongside set seeding");
+		return 1;
+	}
+	if (!super_flags && !seeding_flag && !check_seeding &&
+	    !(random_fsid || new_fsid_str)) {
 		error("at least one option should be specified");
 		print_usage();
 		return 1;
@@ -512,6 +531,12 @@ int main(int argc, char *argv[])
 		total++;
 	}
 
+	if (check_seeding) {
+		check_seeding_flag(root);
+		success++;
+		total++;
+	}
+
 	if (super_flags) {
 		ret = set_super_incompat_flags(root, super_flags);
 		if (!ret)
-- 
2.13.7


  reply	other threads:[~2019-01-03 23:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-03 23:22 [PATCH 0/1] btrfs-progs: btrfstune: print seeding status David Disseldorp
2019-01-03 23:22 ` David Disseldorp [this message]
2019-01-04  7:05   ` [PATCH 1/1] " Nikolay Borisov
2019-01-04 10:26     ` David Disseldorp
2019-01-04 12:09       ` Anand Jain
2019-01-04 13:18       ` Nikolay Borisov
2019-01-04 13:34         ` David Disseldorp
2019-01-05  5:45           ` Anand Jain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190103232239.11931-2-ddiss@suse.de \
    --to=ddiss@suse.de \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).