linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Subject: [PATCH 4/7] btrfs-progs: dedup: Add status subcommand
Date: Tue, 29 Dec 2015 16:01:06 +0800	[thread overview]
Message-ID: <1451376069-30414-5-git-send-email-quwenruo@cn.fujitsu.com> (raw)
In-Reply-To: <1451376069-30414-1-git-send-email-quwenruo@cn.fujitsu.com>

Add status subcommand for dedup command group.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 Documentation/btrfs-dedup.asciidoc |  3 ++
 cmds-dedup.c                       | 72 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 75 insertions(+)

diff --git a/Documentation/btrfs-dedup.asciidoc b/Documentation/btrfs-dedup.asciidoc
index 08d1050..8b605fb 100644
--- a/Documentation/btrfs-dedup.asciidoc
+++ b/Documentation/btrfs-dedup.asciidoc
@@ -54,6 +54,9 @@ If *LIMIT* is zero, there will be no limit at all. Use with caution as it can
 use up all the memory for dedup hash.
 Default value is 4096 if using 'inmemory' backend.
 
+*status* <path>::
+Show current in-band de-duplication status of a filesystem.
+
 BACKENDS
 --------
 Btrfs in-band de-duplication support two different backends with their own
diff --git a/cmds-dedup.c b/cmds-dedup.c
index f15c2c2..5792420 100644
--- a/cmds-dedup.c
+++ b/cmds-dedup.c
@@ -195,11 +195,83 @@ out:
 	return 0;
 }
 
+static const char * const cmd_dedup_status_usage[] = {
+	"btrfs dedup status <path>",
+	"Show current in-band(write time) de-duplication status of a btrfs.",
+	NULL
+};
+
+static int cmd_dedup_status(int argc, char **argv)
+{
+	struct btrfs_ioctl_dedup_args dargs;
+	DIR *dirstream;
+	char *path;
+	int fd;
+	int ret;
+	int print_limit = 1;
+
+	if (check_argc_exact(argc, 2))
+		usage(cmd_dedup_status_usage);
+
+	path = argv[1];
+	fd = open_file_or_dir(path, &dirstream);
+	if (fd < 0) {
+		error("failed to open file or directory: %s", path);
+		ret = 1;
+		goto out;
+	}
+	memset(&dargs, 0, sizeof(dargs));
+	dargs.cmd = BTRFS_DEDUP_CTL_STATUS;
+
+	ret = ioctl(fd, BTRFS_IOC_DEDUP_CTL, &dargs);
+	if (ret < 0) {
+		error("failed to get inband deduplication status: %s",
+		      strerror(errno));
+		ret = 1;
+		goto out;
+	}
+	ret = 0;
+	if (dargs.status == 0) {
+		printf("Status: Disabled\n");
+		goto out;
+	}
+	printf("Status: Enabled\n");
+
+	if (dargs.hash_type == BTRFS_DEDUP_HASH_SHA256)
+		printf("Hash algorithm: SHA-256\n");
+	else
+		printf("Hash algorithm: Unrecognized(%x)\n",
+			dargs.hash_type);
+
+	if (dargs.backend == BTRFS_DEDUP_BACKEND_INMEMORY) {
+		printf("Backend: In-memory\n");
+		print_limit = 1;
+	} else if (dargs.backend == BTRFS_DEDUP_BACKEND_ONDISK) {
+		printf("Backend: On-disk\n");
+		print_limit = 0;
+	} else  {
+		printf("Backend: Unrecognized(%x)\n",
+			dargs.backend);
+	}
+
+	printf("Dedup Blocksize: %llu\n", dargs.blocksize);
+
+	if (print_limit) {
+		printf("Current number of hash: %llu\n", dargs.current_nr);
+		printf("Max number of hash: %llu\n", dargs.limit_nr);
+	}
+out:
+	close_file_or_dir(fd, dirstream);
+	return ret;
+}
+
 const struct cmd_group dedup_cmd_group = {
 	dedup_cmd_group_usage, dedup_cmd_group_info, {
 		{ "enable", cmd_dedup_enable, cmd_dedup_enable_usage, NULL, 0},
 		{ "disable", cmd_dedup_disable, cmd_dedup_disable_usage,
 		  NULL, 0},
+		{ "status", cmd_dedup_status, cmd_dedup_status_usage,
+		  NULL, 0},
 		NULL_CMD_STRUCT
 	}
 };
-- 
2.6.4




  parent reply	other threads:[~2015-12-29  8:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-29  8:01 [PATCH 0/7] btrfs-progs: Support for in-band deduplication Qu Wenruo
2015-12-29  8:01 ` [PATCH 1/7] btrfs-progs: Basic framework for dedup command group Qu Wenruo
2015-12-29  8:01 ` [PATCH 2/7] btrfs-progs: dedup: Add enable command " Qu Wenruo
2015-12-29  8:01 ` [PATCH 3/7] btrfs-progs: dedup: Add disable support for inban deduplication Qu Wenruo
2015-12-29  8:01 ` Qu Wenruo [this message]
2015-12-29  8:01 ` [PATCH 5/7] btrfs-progs: Add dedup feature for mkfs and convert Qu Wenruo
2015-12-29  8:01 ` [PATCH 6/7] btrfs: dedup: Add show-super support for new DEDUP flag Qu Wenruo
2015-12-29  8:01 ` [PATCH 7/7] btrfs-progs: dedup-tree: Add dedup tree support Qu Wenruo

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=1451376069-30414-5-git-send-email-quwenruo@cn.fujitsu.com \
    --to=quwenruo@cn.fujitsu.com \
    --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).