From patchwork Thu Jan 14 05:57:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 8029711 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id BEE249F1C0 for ; Thu, 14 Jan 2016 06:00:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E1121204A2 for ; Thu, 14 Jan 2016 06:00:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DE4BA20444 for ; Thu, 14 Jan 2016 06:00:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752322AbcANGAW (ORCPT ); Thu, 14 Jan 2016 01:00:22 -0500 Received: from cn.fujitsu.com ([59.151.112.132]:18653 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752172AbcANGAS (ORCPT ); Thu, 14 Jan 2016 01:00:18 -0500 X-IronPort-AV: E=Sophos;i="5.20,346,1444665600"; d="scan'208";a="2575610" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 14 Jan 2016 14:00:10 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id BD47741896E7 for ; Thu, 14 Jan 2016 13:59:53 +0800 (CST) Received: from localhost.localdomain (10.167.226.34) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Thu, 14 Jan 2016 13:59:53 +0800 From: Qu Wenruo To: Subject: [PATCH v3 4/8] btrfs-progs: dedup: Add status subcommand Date: Thu, 14 Jan 2016 13:57:46 +0800 Message-ID: <1452751070-2460-5-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1452751070-2460-1-git-send-email-quwenruo@cn.fujitsu.com> References: <1452751070-2460-1-git-send-email-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.34] X-yoursite-MailScanner-ID: BD47741896E7.AD3D6 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: quwenruo@cn.fujitsu.com X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add status subcommand for dedup command group. Signed-off-by: Qu Wenruo --- 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* :: +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 ", + "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 } };