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 v3 08/16] btrfs: dedup: Implement btrfs_dedup_calc_hash interface
Date: Thu, 7 Jan 2016 09:08:09 +0800	[thread overview]
Message-ID: <1452128897-5433-9-git-send-email-quwenruo@cn.fujitsu.com> (raw)
In-Reply-To: <1452128897-5433-1-git-send-email-quwenruo@cn.fujitsu.com>

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

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

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: Wang Xiaoguang <wangxg.fnst@cn.fujitsu.com>
---
 fs/btrfs/dedup.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/fs/btrfs/dedup.c b/fs/btrfs/dedup.c
index 4863cf2..4f24a2c 100644
--- a/fs/btrfs/dedup.c
+++ b/fs/btrfs/dedup.c
@@ -499,3 +499,60 @@ int btrfs_dedup_search(struct inode *inode, u64 file_pos,
 	}
 	return ret;
 }
+
+static int hash_data(struct btrfs_dedup_info *dedup_info, const char *data,
+		     u64 length, struct btrfs_dedup_hash *hash)
+{
+	struct crypto_shash *tfm = dedup_info->dedup_driver;
+	struct {
+		struct shash_desc desc;
+		char ctx[crypto_shash_descsize(tfm)];
+	} sdesc;
+	int ret;
+
+	sdesc.desc.tfm = tfm;
+	sdesc.desc.flags = 0;
+
+	ret = crypto_shash_digest(&sdesc.desc, data, length,
+				  (char *)(hash->hash));
+	return ret;
+}
+
+int btrfs_dedup_calc_hash(struct btrfs_root *root, struct inode *inode,
+			  u64 start, struct btrfs_dedup_hash *hash)
+{
+	struct page *p;
+	struct btrfs_dedup_info *dedup_info = root->fs_info->dedup_info;
+	char *data;
+	int i;
+	int ret;
+	u64 dedup_bs;
+	u64 sectorsize = root->sectorsize;
+
+	if (!dedup_info || !hash)
+		return 0;
+
+	WARN_ON(!IS_ALIGNED(start, sectorsize));
+
+	dedup_bs = dedup_info->blocksize;
+	sectorsize = root->sectorsize;
+
+	data = kmalloc(dedup_bs, GFP_NOFS);
+	if (!data)
+		return -ENOMEM;
+	for (i = 0; sectorsize * i < dedup_bs; i++) {
+		char *d;
+
+		/* TODO: Add support for subpage size case */
+		p = find_get_page(inode->i_mapping,
+				  (start >> PAGE_CACHE_SHIFT) + i);
+		WARN_ON(!p);
+		d = kmap_atomic(p);
+		memcpy((data + sectorsize * i), d, sectorsize);
+		kunmap_atomic(d);
+		page_cache_release(p);
+	}
+	ret = hash_data(dedup_info, data, dedup_bs, hash);
+	kfree(data);
+	return ret;
+}
-- 
2.6.4




  parent reply	other threads:[~2016-01-07  1:08 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-07  1:08 [PATCH v3 00/14][For 4.6] Btrfs: Add inband (write time) de-duplication framework Qu Wenruo
2016-01-07  1:08 ` [PATCH v3 01/16] btrfs: dedup: Introduce dedup framework and its header Qu Wenruo
2016-01-07  1:08 ` [PATCH v3 02/16] btrfs: dedup: Introduce function to initialize dedup info Qu Wenruo
2016-01-07  1:08 ` [PATCH v3 03/16] btrfs: dedup: Introduce function to add hash into in-memory tree Qu Wenruo
2016-01-07  1:08 ` [PATCH v3 04/16] btrfs: dedup: Introduce function to remove hash from " Qu Wenruo
2016-01-07  1:08 ` [PATCH v3 05/16] btrfs: delayed-ref: Add support for atomic increasing extent ref Qu Wenruo
2016-01-07  1:08 ` [PATCH v3 06/16] btrfs: delayed_ref: Add support for handle dedup hash Qu Wenruo
2016-01-07  1:08 ` [PATCH v3 07/16] btrfs: dedup: Introduce function to search for an existing hash Qu Wenruo
2016-01-07  1:08 ` Qu Wenruo [this message]
2016-01-07 13:21   ` [PATCH v3 08/16] btrfs: dedup: Implement btrfs_dedup_calc_hash interface kbuild test robot
2016-01-07  1:08 ` [PATCH v3 09/16] btrfs: ordered-extent: Add support for dedup Qu Wenruo
2016-01-07  1:08 ` [PATCH v3 10/16] btrfs: dedup: Inband in-memory only de-duplication implement Qu Wenruo
2016-01-07  1:08 ` [PATCH v3 11/16] btrfs: dedup: Add basic tree structure for on-disk dedup method Qu Wenruo
2016-01-07  1:08 ` [PATCH v3 12/16] btrfs: dedup: Introduce interfaces to resume and cleanup dedup info Qu Wenruo
2016-01-07  1:08 ` [PATCH v3 13/16] btrfs: dedup: Add support for on-disk hash search Qu Wenruo
2016-01-07  1:08 ` [PATCH v3 14/16] btrfs: dedup: Add support to delete hash for on-disk backend Qu Wenruo
2016-01-07  1:08 ` [PATCH v3 15/16] btrfs: dedup: Add support for adding " Qu Wenruo
2016-01-07  1:08 ` [PATCH v3 16/16] btrfs: dedup: Add ioctl for inband deduplication 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=1452128897-5433-9-git-send-email-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.