All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: linux-btrfs@vger.kernel.org
Cc: Wang Xiaoguang <wangxg.fnst@cn.fujitsu.com>
Subject: [PATCH v12.2 08/15] btrfs: dedupe: Implement btrfs_dedupe_calc_hash interface
Date: Tue, 19 Jul 2016 16:50:43 +0800	[thread overview]
Message-ID: <20160719085050.30564-9-quwenruo@cn.fujitsu.com> (raw)
In-Reply-To: <20160719085050.30564-1-quwenruo@cn.fujitsu.com>

From: Wang Xiaoguang <wangxg.fnst@cn.fujitsu.com>

Unlike in-memory or on-disk dedupe method, only SHA256 hash method is
supported yet, so implement btrfs_dedupe_calc_hash() interface using
SHA256.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: Wang Xiaoguang <wangxg.fnst@cn.fujitsu.com>
Reviewed-by: Josef Bacik <jbacik@fb.com>
---
 fs/btrfs/dedupe.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/fs/btrfs/dedupe.c b/fs/btrfs/dedupe.c
index eb1b110..6296b65 100644
--- a/fs/btrfs/dedupe.c
+++ b/fs/btrfs/dedupe.c
@@ -639,3 +639,49 @@ int btrfs_dedupe_search(struct btrfs_fs_info *fs_info,
 	}
 	return ret;
 }
+
+int btrfs_dedupe_calc_hash(struct btrfs_fs_info *fs_info,
+			   struct inode *inode, u64 start,
+			   struct btrfs_dedupe_hash *hash)
+{
+	int i;
+	int ret;
+	struct page *p;
+	struct btrfs_dedupe_info *dedupe_info = fs_info->dedupe_info;
+	struct crypto_shash *tfm = dedupe_info->dedupe_driver;
+	SHASH_DESC_ON_STACK(sdesc, tfm);
+	u64 dedupe_bs;
+	u64 sectorsize = BTRFS_I(inode)->root->sectorsize;
+
+	if (!fs_info->dedupe_enabled || !hash)
+		return 0;
+
+	if (WARN_ON(dedupe_info == NULL))
+		return -EINVAL;
+
+	WARN_ON(!IS_ALIGNED(start, sectorsize));
+
+	dedupe_bs = dedupe_info->blocksize;
+
+	sdesc->tfm = tfm;
+	sdesc->flags = 0;
+	ret = crypto_shash_init(sdesc);
+	if (ret)
+		return ret;
+	for (i = 0; sectorsize * i < dedupe_bs; i++) {
+		char *d;
+
+		p = find_get_page(inode->i_mapping,
+				  (start >> PAGE_SHIFT) + i);
+		if (WARN_ON(!p))
+			return -ENOENT;
+		d = kmap(p);
+		ret = crypto_shash_update(sdesc, d, sectorsize);
+		kunmap(p);
+		put_page(p);
+		if (ret)
+			return ret;
+	}
+	ret = crypto_shash_final(sdesc, hash->hash);
+	return ret;
+}
-- 
2.9.0




  parent reply	other threads:[~2016-07-19  8:51 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-19  8:50 [PATCH v12.2 00/15] Btrfs In-band De-duplication Qu Wenruo
2016-07-19  8:50 ` [PATCH v12.2 01/15] btrfs: expand btrfs_set_extent_delalloc() and its friends to support in-band dedupe and subpage size patchset Qu Wenruo
2016-08-09  1:19   ` Qu Wenruo
2016-09-07 14:53     ` David Sterba
2016-07-19  8:50 ` [PATCH v12.2 02/15] btrfs: dedupe: Introduce dedupe framework and its header Qu Wenruo
2016-07-19  8:50 ` [PATCH v12.2 03/15] btrfs: dedupe: Introduce function to initialize dedupe info Qu Wenruo
2016-07-25  8:17   ` kbuild test robot
2016-07-19  8:50 ` [PATCH v12.2 04/15] btrfs: dedupe: Introduce function to add hash into in-memory tree Qu Wenruo
2016-07-19  8:50 ` [PATCH v12.2 05/15] btrfs: dedupe: Introduce function to remove hash from " Qu Wenruo
2016-07-19  8:50 ` [PATCH v12.2 06/15] btrfs: delayed-ref: Add support for increasing data ref under spinlock Qu Wenruo
2016-07-19  8:50 ` [PATCH v12.2 07/15] btrfs: dedupe: Introduce function to search for an existing hash Qu Wenruo
2016-07-19  8:50 ` Qu Wenruo [this message]
2016-07-19  8:50 ` [PATCH v12.2 09/15] btrfs: ordered-extent: Add support for dedupe Qu Wenruo
2016-07-19  8:50 ` [PATCH v12.2 10/15] btrfs: dedupe: Inband in-memory only de-duplication implement Qu Wenruo
2016-07-19  8:50 ` [PATCH v12.2 11/15] btrfs: dedupe: Add ioctl for inband dedupelication Qu Wenruo
2016-07-19  8:50 ` [PATCH v12.2 12/15] btrfs: relocation: Enhance error handling to avoid BUG_ON Qu Wenruo
2016-07-19  8:50 ` [PATCH v12.2 13/15] btrfs: improve inode's outstanding_extents computation Qu Wenruo
2016-07-19  8:50 ` [PATCH v12.2 14/15] btrfs: dedupe: fix false ENOSPC Qu Wenruo
2016-07-19  8:50 ` [PATCH v12.2 15/15] btrfs: dedupe: Introduce new reconfigure ioctl Qu Wenruo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160719085050.30564-9-quwenruo@cn.fujitsu.com \
    --to=quwenruo@cn.fujitsu.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=wangxg.fnst@cn.fujitsu.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.