From patchwork Tue May 15 08:56:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lu Fengqi X-Patchwork-Id: 10400431 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DF818600F4 for ; Tue, 15 May 2018 08:56:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE12028668 for ; Tue, 15 May 2018 08:56:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B2E5B286B3; Tue, 15 May 2018 08:56:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E51EA286AD for ; Tue, 15 May 2018 08:56:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752597AbeEOI4a (ORCPT ); Tue, 15 May 2018 04:56:30 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:8734 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752481AbeEOI4W (ORCPT ); Tue, 15 May 2018 04:56:22 -0400 X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="39939245" Received: from localhost (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 15 May 2018 16:56:20 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id 961024B41E79; Tue, 15 May 2018 16:56:18 +0800 (CST) Received: from fnst.localdomain (10.167.226.155) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.399.0; Tue, 15 May 2018 16:56:22 +0800 From: Lu Fengqi To: CC: Qu Wenruo Subject: [PATCH v10.2 5/5] btrfs-progs: dedupe: introduce reconfigure subcommand Date: Tue, 15 May 2018 16:56:06 +0800 Message-ID: <20180515085606.18084-6-lufq.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180515085606.18084-1-lufq.fnst@cn.fujitsu.com> References: <20180515085606.18084-1-lufq.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.155] X-yoursite-MailScanner-ID: 961024B41E79.ABE2F X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: lufq.fnst@cn.fujitsu.com Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Qu Wenruo Introduce reconfigure subcommand to co-operate with new kernel ioctl modification. Signed-off-by: Qu Wenruo --- Documentation/btrfs-dedupe-inband.asciidoc | 7 ++ cmds-dedupe-ib.c | 75 +++++++++++++++++----- 2 files changed, 66 insertions(+), 16 deletions(-) diff --git a/Documentation/btrfs-dedupe-inband.asciidoc b/Documentation/btrfs-dedupe-inband.asciidoc index df068c31ca3a..5fc4bb0d5940 100644 --- a/Documentation/btrfs-dedupe-inband.asciidoc +++ b/Documentation/btrfs-dedupe-inband.asciidoc @@ -86,6 +86,13 @@ And compression has higher priority than in-band de-duplication, means if compression and de-duplication is enabled at the same time, only compression will work. +*reconfigure* [options] :: +Re-configure in-band de-duplication parameters of a filesystem. ++ +In-band de-duplication must be enbaled first before re-configuration. ++ +[Options] are the same with 'btrfs dedupe-inband enable'. + *status* :: Show current in-band de-duplication status of a filesystem. diff --git a/cmds-dedupe-ib.c b/cmds-dedupe-ib.c index 854cbda131a3..925d5a8f756a 100644 --- a/cmds-dedupe-ib.c +++ b/cmds-dedupe-ib.c @@ -56,7 +56,6 @@ static const char * const cmd_dedupe_ib_enable_usage[] = { NULL }; - #define report_fatal_parameter(dargs, old, member, type, err_val, fmt) \ ({ \ if (dargs->member != old->member && \ @@ -88,6 +87,12 @@ static void report_parameter_error(struct btrfs_ioctl_dedupe_args *dargs, } report_option_parameter(dargs, old, flags, u8, -1, x); } + + if (dargs->status == 0 && old->cmd == BTRFS_DEDUPE_CTL_RECONF) { + error("must enable dedupe before reconfiguration"); + return; + } + if (report_fatal_parameter(dargs, old, cmd, u16, -1, u) || report_fatal_parameter(dargs, old, blocksize, u64, -1, llu) || report_fatal_parameter(dargs, old, backend, u16, -1, u) || @@ -100,14 +105,17 @@ static void report_parameter_error(struct btrfs_ioctl_dedupe_args *dargs, old->limit_nr, old->limit_mem); } -static int cmd_dedupe_ib_enable(int argc, char **argv) +static int enable_reconfig_dedupe(int argc, char **argv, int reconf) { int ret; int fd = -1; char *path; u64 blocksize = BTRFS_DEDUPE_BLOCKSIZE_DEFAULT; + int blocksize_set = 0; u16 hash_algo = BTRFS_DEDUPE_HASH_SHA256; + int hash_algo_set = 0; u16 backend = BTRFS_DEDUPE_BACKEND_INMEMORY; + int backend_set = 0; u64 limit_nr = 0; u64 limit_mem = 0; u64 sys_mem = 0; @@ -129,20 +137,22 @@ static int cmd_dedupe_ib_enable(int argc, char **argv) { NULL, 0, NULL, 0} }; - c = getopt_long(argc, argv, "s:b:a:l:m:", long_options, NULL); + c = getopt_long(argc, argv, "s:b:a:l:m:f", long_options, NULL); if (c < 0) break; switch (c) { case 's': - if (!strcasecmp("inmemory", optarg)) + if (!strcasecmp("inmemory", optarg)) { backend = BTRFS_DEDUPE_BACKEND_INMEMORY; - else { + backend_set = 1; + } else { error("unsupported dedupe backend: %s", optarg); exit(1); } break; case 'b': blocksize = parse_size(optarg); + blocksize_set = 1; break; case 'a': if (strcmp("sha256", optarg)) { @@ -226,26 +236,40 @@ static int cmd_dedupe_ib_enable(int argc, char **argv) return 1; } memset(&dargs, -1, sizeof(dargs)); - dargs.cmd = BTRFS_DEDUPE_CTL_ENABLE; - dargs.blocksize = blocksize; - dargs.hash_algo = hash_algo; - dargs.limit_nr = limit_nr; - dargs.limit_mem = limit_mem; - dargs.backend = backend; - if (force) - dargs.flags |= BTRFS_DEDUPE_FLAG_FORCE; - else - dargs.flags = 0; + if (reconf) { + dargs.cmd = BTRFS_DEDUPE_CTL_RECONF; + if (blocksize_set) + dargs.blocksize = blocksize; + if (hash_algo_set) + dargs.hash_algo = hash_algo; + if (backend_set) + dargs.backend = backend; + dargs.limit_nr = limit_nr; + dargs.limit_mem = limit_mem; + } else { + dargs.cmd = BTRFS_DEDUPE_CTL_ENABLE; + dargs.blocksize = blocksize; + dargs.hash_algo = hash_algo; + dargs.limit_nr = limit_nr; + dargs.limit_mem = limit_mem; + dargs.backend = backend; + if (force) + dargs.flags |= BTRFS_DEDUPE_FLAG_FORCE; + else + dargs.flags = 0; + } memcpy(&backup, &dargs, sizeof(dargs)); ret = ioctl(fd, BTRFS_IOC_DEDUPE_CTL, &dargs); if (ret < 0) { - error("failed to enable inband deduplication: %s", + error("failed to (%s) inband deduplication: %s", + reconf ? "reconfigure" : "enable", strerror(errno)); report_parameter_error(&dargs, &backup); ret = 1; goto out; } + report_parameter_error(&dargs, &backup); ret = 0; mem_check: if (!force && dargs.limit_mem > sys_mem / 4) { @@ -261,6 +285,10 @@ out: close_file_or_dir(fd, dirstream); return ret; } +static int cmd_dedupe_ib_enable(int argc, char **argv) +{ + return enable_reconfig_dedupe(argc, argv, 0); +} static const char * const cmd_dedupe_ib_disable_usage[] = { "btrfs dedupe disable ", @@ -381,6 +409,19 @@ out: return ret; } +static int cmd_dedupe_ib_reconf(int argc, char **argv) +{ + return enable_reconfig_dedupe(argc, argv, 1); +} + +static const char * const cmd_dedupe_ib_reconf_usage[] = { + "btrfs dedupe-inband reconfigure [options] ", + "Reconfigure in-band(write time) de-duplication of a btrfs.", + "", + "Options are the same as 'btrfs dedupe-inband enable'", + NULL +}; + const struct cmd_group dedupe_ib_cmd_group = { dedupe_ib_cmd_group_usage, dedupe_ib_cmd_group_info, { { "enable", cmd_dedupe_ib_enable, cmd_dedupe_ib_enable_usage, @@ -389,6 +430,8 @@ const struct cmd_group dedupe_ib_cmd_group = { NULL, 0}, { "status", cmd_dedupe_ib_status, cmd_dedupe_ib_status_usage, NULL, 0}, + { "reconfigure", cmd_dedupe_ib_reconf, + cmd_dedupe_ib_reconf_usage, NULL, 0}, NULL_CMD_STRUCT } };