From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Cc: Wang Xiaoguang <wangxg.fnst@cn.fujitsu.com>
Subject: [PATCH 13/14] btrfs: dedup: Add support to delete hash for on-disk backend
Date: Tue, 29 Dec 2015 16:01:22 +0800 [thread overview]
Message-ID: <1451376083-30474-14-git-send-email-quwenruo@cn.fujitsu.com> (raw)
In-Reply-To: <1451376083-30474-1-git-send-email-quwenruo@cn.fujitsu.com>
Now on-disk backend can delete hash now.
Signed-off-by: Wang Xiaoguang <wangxg.fnst@cn.fujitsu.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
fs/btrfs/dedup.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+)
diff --git a/fs/btrfs/dedup.c b/fs/btrfs/dedup.c
index 82e21a6..704c3c7 100644
--- a/fs/btrfs/dedup.c
+++ b/fs/btrfs/dedup.c
@@ -468,6 +468,58 @@ static int inmem_del(struct btrfs_dedup_info *dedup_info, u64 bytenr)
return 0;
}
+static int ondisk_del(struct btrfs_trans_handle *trans,
+ struct btrfs_dedup_info *dedup_info, u64 bytenr)
+{
+ struct btrfs_root *dedup_root = dedup_info->dedup_root;
+ struct btrfs_path *path;
+ struct btrfs_key key;
+ int ret;
+
+ path = btrfs_alloc_path();
+ if (!path)
+ return -ENOMEM;
+
+ key.objectid = bytenr;
+ key.type = BTRFS_DEDUP_BYTENR_ITEM_KEY;
+ key.offset = 0;
+
+ mutex_lock(&dedup_info->ondisk_lock);
+
+ ret = btrfs_search_slot(trans, dedup_root, &key, path, -1, 1);
+ if (ret < 0)
+ goto out;
+
+ /* There should be at most one item with same objectid and type */
+ btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
+ if (key.objectid != bytenr || key.type != BTRFS_DEDUP_BYTENR_ITEM_KEY) {
+ ret = 0;
+ goto out;
+ }
+
+ btrfs_del_item(trans, dedup_root, path);
+ btrfs_release_path(path);
+
+ /* Search for hash item and delete it */
+ key.objectid = key.offset;
+ key.type = BTRFS_DEDUP_HASH_ITEM_KEY;
+ key.offset = bytenr;
+
+ ret = btrfs_search_slot(trans, dedup_root, &key, path, -1, 1);
+ if (WARN_ON(ret > 0)) {
+ ret = -ENOENT;
+ goto out;
+ }
+ if (ret < 0)
+ goto out;
+ btrfs_del_item(trans, dedup_root, path);
+
+out:
+ btrfs_free_path(path);
+ mutex_unlock(&dedup_info->ondisk_lock);
+ return ret;
+}
+
/* Remove a dedup hash from dedup tree */
int btrfs_dedup_del(struct btrfs_trans_handle *trans, struct btrfs_root *root,
u64 bytenr)
@@ -480,6 +532,8 @@ int btrfs_dedup_del(struct btrfs_trans_handle *trans, struct btrfs_root *root,
if (dedup_info->backend == BTRFS_DEDUP_BACKEND_INMEMORY)
return inmem_del(dedup_info, bytenr);
+ if (dedup_info->backend == BTRFS_DEDUP_BACKEND_ONDISK)
+ return ondisk_del(trans, dedup_info, bytenr);
return -EINVAL;
}
--
2.6.4
next prev parent reply other threads:[~2015-12-29 8:02 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-29 8:01 [PATCH v2 00/14][For 4.6] Btrfs: Add inband (write time) de-duplication framework Qu Wenruo
2015-12-29 8:01 ` [PATCH 01/14] btrfs: dedup: Introduce dedup framework and its header Qu Wenruo
2015-12-29 8:01 ` [PATCH 02/14] btrfs: dedup: Introduce function to initialize dedup info Qu Wenruo
2015-12-29 8:01 ` [PATCH 03/14] btrfs: dedup: Introduce function to add hash into in-memory tree Qu Wenruo
2015-12-29 8:01 ` [PATCH 04/14] btrfs: dedup: Introduce function to remove hash from " Qu Wenruo
2015-12-29 8:01 ` [PATCH 05/14] btrfs: dedup: Introduce function to search for an existing hash Qu Wenruo
2015-12-29 8:01 ` [PATCH 06/14] btrfs: dedup: Implement btrfs_dedup_calc_hash interface Qu Wenruo
2015-12-29 8:01 ` [PATCH 07/14] btrfs: ordered-extent: Add support for dedup Qu Wenruo
2015-12-29 8:01 ` [PATCH 08/14] btrfs: dedup: Inband in-memory only de-duplication implement Qu Wenruo
2015-12-29 8:01 ` [PATCH 09/14] btrfs: dedup: Add basic tree structure for on-disk dedup method Qu Wenruo
2015-12-29 8:01 ` [PATCH 10/14] btrfs: dedup: Introduce interfaces to resume and cleanup dedup info Qu Wenruo
2015-12-29 8:01 ` [PATCH 11/14] btrfs: dedup: Add support for on-disk hash search Qu Wenruo
2015-12-29 8:01 ` [PATCH 12/14] btrfs: dedup: Add support for adding hash for on-disk backend Qu Wenruo
2015-12-29 8:01 ` Qu Wenruo [this message]
2015-12-29 8:01 ` [PATCH 14/14] 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=1451376083-30474-14-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).