From patchwork Fri Apr 1 06:37:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 8720661 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 3F6DDC0553 for ; Fri, 1 Apr 2016 06:38:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 30C20203AA for ; Fri, 1 Apr 2016 06:38:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 397582039E for ; Fri, 1 Apr 2016 06:38:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758831AbcDAGiG (ORCPT ); Fri, 1 Apr 2016 02:38:06 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:30468 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1758120AbcDAGiD (ORCPT ); Fri, 1 Apr 2016 02:38:03 -0400 X-IronPort-AV: E=Sophos;i="5.20,367,1444665600"; d="scan'208";a="419998" Received: from unknown (HELO cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 01 Apr 2016 14:37:59 +0800 Received: from localhost.localdomain (unknown [10.167.226.34]) by cn.fujitsu.com (Postfix) with ESMTP id 885BE4056406 for ; Fri, 1 Apr 2016 14:37:53 +0800 (CST) From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH v7 3/8] btrfs-progs: dedupe: Add disable support for inband dedupelication Date: Fri, 1 Apr 2016 14:37:45 +0800 Message-Id: <1459492670-31596-4-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1459492670-31596-1-git-send-email-quwenruo@cn.fujitsu.com> References: <1459492670-31596-1-git-send-email-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-yoursite-MailScanner-ID: 885BE4056406.AC469 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: quwenruo@cn.fujitsu.com X-Spam-Status: No, score=-7.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 disable subcommand for dedupe command group. Signed-off-by: Qu Wenruo --- Documentation/btrfs-dedupe.asciidoc | 5 +++++ btrfs-completion | 2 +- cmds-dedupe.c | 42 +++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/Documentation/btrfs-dedupe.asciidoc b/Documentation/btrfs-dedupe.asciidoc index 8ab40ab..28fe05f 100644 --- a/Documentation/btrfs-dedupe.asciidoc +++ b/Documentation/btrfs-dedupe.asciidoc @@ -21,6 +21,11 @@ use with caution. SUBCOMMAND ---------- +*disable* :: +Disable in-band de-duplication for a filesystem. ++ +This will trash all stored dedupe hash. ++ *enable* [options] :: Enable in-band de-duplication for a filesystem. + diff --git a/btrfs-completion b/btrfs-completion index 50f7ea2..9a6c73b 100644 --- a/btrfs-completion +++ b/btrfs-completion @@ -40,7 +40,7 @@ _btrfs() commands_property='get set list' commands_quota='enable disable rescan' commands_qgroup='assign remove create destroy show limit' - commands_dedupe='enable' + commands_dedupe='enable disable' commands_replace='start status cancel' if [[ "$cur" == -* && $cword -le 3 && "$cmd" != "help" ]]; then diff --git a/cmds-dedupe.c b/cmds-dedupe.c index d9dcb10..64ac0f2 100644 --- a/cmds-dedupe.c +++ b/cmds-dedupe.c @@ -190,9 +190,51 @@ out: return ret; } +static const char * const cmd_dedupe_disable_usage[] = { + "btrfs dedupe disable ", + "Disable in-band(write time) de-duplication of a btrfs.", + NULL +}; + +static int cmd_dedupe_disable(int argc, char **argv) +{ + struct btrfs_ioctl_dedupe_args dargs; + DIR *dirstream; + char *path; + int fd; + int ret; + + if (check_argc_exact(argc, 2)) + usage(cmd_dedupe_disable_usage); + + path = argv[1]; + fd = open_file_or_dir(path, &dirstream); + if (fd < 0) { + error("failed to open file or directory: %s", path); + return 1; + } + memset(&dargs, 0, sizeof(dargs)); + dargs.cmd = BTRFS_DEDUPE_CTL_DISABLE; + + ret = ioctl(fd, BTRFS_IOC_DEDUPE_CTL, &dargs); + if (ret < 0) { + error("failed to disable inband deduplication: %s", + strerror(errno)); + ret = 1; + goto out; + } + ret = 0; + +out: + close_file_or_dir(fd, dirstream); + return 0; +} + const struct cmd_group dedupe_cmd_group = { dedupe_cmd_group_usage, dedupe_cmd_group_info, { { "enable", cmd_dedupe_enable, cmd_dedupe_enable_usage, NULL, 0}, + { "disable", cmd_dedupe_disable, cmd_dedupe_disable_usage, + NULL, 0}, NULL_CMD_STRUCT } };