From patchwork Fri Apr 1 06:35:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 8720451 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 B4EC19FC89 for ; Fri, 1 Apr 2016 06:35:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C5A98203B1 for ; Fri, 1 Apr 2016 06:35:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BA46A203AA for ; Fri, 1 Apr 2016 06:35:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758346AbcDAGfk (ORCPT ); Fri, 1 Apr 2016 02:35:40 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:12218 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1754119AbcDAGfi (ORCPT ); Fri, 1 Apr 2016 02:35:38 -0400 X-IronPort-AV: E=Sophos;i="5.20,367,1444665600"; d="scan'208";a="419981" Received: from unknown (HELO cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 01 Apr 2016 14:35:22 +0800 Received: from localhost.localdomain (unknown [10.167.226.34]) by cn.fujitsu.com (Postfix) with ESMTP id 810F84056411; Fri, 1 Apr 2016 14:35:20 +0800 (CST) From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: Wang Xiaoguang Subject: [PATCH v10 13/21] btrfs: dedupe: add a property handler for online dedupe Date: Fri, 1 Apr 2016 14:35:04 +0800 Message-Id: <1459492512-31435-14-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1459492512-31435-1-git-send-email-quwenruo@cn.fujitsu.com> References: <1459492512-31435-1-git-send-email-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-yoursite-MailScanner-ID: 810F84056411.AAED4 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 From: Wang Xiaoguang We use btrfs extended attribute "btrfs.dedupe" to record per-file online dedupe status, so add a dedupe property handler. Signed-off-by: Wang Xiaoguang --- fs/btrfs/props.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/fs/btrfs/props.c b/fs/btrfs/props.c index 3699212..a430886 100644 --- a/fs/btrfs/props.c +++ b/fs/btrfs/props.c @@ -42,6 +42,11 @@ static int prop_compression_apply(struct inode *inode, size_t len); static const char *prop_compression_extract(struct inode *inode); +static int prop_dedupe_validate(const char *value, size_t len); +static int prop_dedupe_apply(struct inode *inode, const char *value, + size_t len); +static const char *prop_dedupe_extract(struct inode *inode); + static struct prop_handler prop_handlers[] = { { .xattr_name = XATTR_BTRFS_PREFIX "compression", @@ -50,6 +55,13 @@ static struct prop_handler prop_handlers[] = { .extract = prop_compression_extract, .inheritable = 1 }, + { + .xattr_name = XATTR_BTRFS_PREFIX "dedupe", + .validate = prop_dedupe_validate, + .apply = prop_dedupe_apply, + .extract = prop_dedupe_extract, + .inheritable = 1 + }, }; void __init btrfs_props_init(void) @@ -426,4 +438,33 @@ static const char *prop_compression_extract(struct inode *inode) return NULL; } +static int prop_dedupe_validate(const char *value, size_t len) +{ + if (!strncmp("disable", value, len)) + return 0; + + return -EINVAL; +} + +static int prop_dedupe_apply(struct inode *inode, const char *value, size_t len) +{ + if (len == 0) { + BTRFS_I(inode)->flags &= ~BTRFS_INODE_NODEDUPE; + return 0; + } + + if (!strncmp("disable", value, len)) { + BTRFS_I(inode)->flags |= BTRFS_INODE_NODEDUPE; + return 0; + } + + return -EINVAL; +} + +static const char *prop_dedupe_extract(struct inode *inode) +{ + if (BTRFS_I(inode)->flags & BTRFS_INODE_NODEDUPE) + return "disable"; + return NULL; +}