From patchwork Tue Dec 29 08:01:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 7928931 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 CC4A6BEEE5 for ; Tue, 29 Dec 2015 08:02:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F34222021A for ; Tue, 29 Dec 2015 08:02:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 128B1201F2 for ; Tue, 29 Dec 2015 08:02:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753300AbbL2ICe (ORCPT ); Tue, 29 Dec 2015 03:02:34 -0500 Received: from cn.fujitsu.com ([59.151.112.132]:45782 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1753248AbbL2ICB (ORCPT ); Tue, 29 Dec 2015 03:02:01 -0500 X-IronPort-AV: E=Sophos;i="5.20,346,1444665600"; d="scan'208";a="2059339" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 29 Dec 2015 16:01:31 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 85528409257F for ; Tue, 29 Dec 2015 16:01:12 +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; Tue, 29 Dec 2015 16:01:12 +0800 From: Qu Wenruo To: Subject: [PATCH 3/7] btrfs-progs: dedup: Add disable support for inban deduplication Date: Tue, 29 Dec 2015 16:01:05 +0800 Message-ID: <1451376069-30414-4-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.6.4 In-Reply-To: <1451376069-30414-1-git-send-email-quwenruo@cn.fujitsu.com> References: <1451376069-30414-1-git-send-email-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.34] X-yoursite-MailScanner-ID: 85528409257F.AB6F5 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 disable subcommand for dedup command group. Signed-off-by: Qu Wenruo --- Documentation/btrfs-dedup.asciidoc | 5 +++++ cmds-dedup.c | 42 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/Documentation/btrfs-dedup.asciidoc b/Documentation/btrfs-dedup.asciidoc index 652f22d..08d1050 100644 --- a/Documentation/btrfs-dedup.asciidoc +++ b/Documentation/btrfs-dedup.asciidoc @@ -19,6 +19,11 @@ use with caution. SUBCOMMAND ---------- +*disable* :: +Disable in-band de-duplication for a filesystem. ++ +This will trash all stored dedup hash. ++ *enable* [options] :: Enable in-band de-duplication for a filesystem. + diff --git a/cmds-dedup.c b/cmds-dedup.c index e116f4c..f15c2c2 100644 --- a/cmds-dedup.c +++ b/cmds-dedup.c @@ -155,9 +155,51 @@ out: return ret; } +static const char * const cmd_dedup_disable_usage[] = { + "btrfs dedup disable ", + "Disable in-band(write time) de-duplication of a btrfs.", + NULL +}; + +static int cmd_dedup_disable(int argc, char **argv) +{ + struct btrfs_ioctl_dedup_args dargs; + DIR *dirstream; + char *path; + int fd; + int ret; + + if (check_argc_exact(argc, 2)) + usage(cmd_dedup_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_DEDUP_CTL_DISABLE; + + ret = ioctl(fd, BTRFS_IOC_DEDUP_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 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}, NULL_CMD_STRUCT } };