All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Cc: Qu Wenruo <quwenruo@cn.fujitsu.com>
Subject: [PATCH v14.6 07/14] btrfs: delayed-ref: Add support for increasing data ref under spinlock
Date: Tue, 15 May 2018 16:51:56 +0800	[thread overview]
Message-ID: <20180515085203.17470-8-lufq.fnst@cn.fujitsu.com> (raw)
In-Reply-To: <20180515085203.17470-1-lufq.fnst@cn.fujitsu.com>

From: Qu Wenruo <quwenruo@cn.fujitsu.com>

For in-band dedupe, btrfs needs to increase data ref with delayed_ref
locked, so add a new function btrfs_add_delayed_data_ref_lock() to
increase extent ref with delayed_refs already locked.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
---
 fs/btrfs/delayed-ref.c | 37 +++++++++++++++++++++++++++++--------
 fs/btrfs/delayed-ref.h | 10 ++++++++++
 2 files changed, 39 insertions(+), 8 deletions(-)

diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c
index e1b0651686f7..58a64448d777 100644
--- a/fs/btrfs/delayed-ref.c
+++ b/fs/btrfs/delayed-ref.c
@@ -824,6 +824,31 @@ int btrfs_add_delayed_tree_ref(struct btrfs_fs_info *fs_info,
 	return -ENOMEM;
 }
 
+/*
+ * Do real delayed data ref insert.
+ * Caller must hold delayed_refs->lock and allocation memory
+ * for dref,head_ref and record.
+ */
+void btrfs_add_delayed_data_ref_locked(struct btrfs_fs_info *fs_info,
+			struct btrfs_trans_handle *trans,
+			struct btrfs_delayed_data_ref *dref,
+			struct btrfs_delayed_ref_head *head_ref,
+			struct btrfs_qgroup_extent_record *qrecord,
+			u64 bytenr, u64 num_bytes, u64 parent, u64 ref_root,
+			u64 owner, u64 offset, u64 reserved, int action,
+			int *qrecord_inserted_ret, int *old_ref_mod,
+			int *new_ref_mod)
+{
+	head_ref = add_delayed_ref_head(fs_info, trans, head_ref, qrecord,
+					bytenr, num_bytes, ref_root, reserved,
+					action, 1, 0, qrecord_inserted_ret,
+					old_ref_mod, new_ref_mod);
+
+	add_delayed_data_ref(fs_info, trans, head_ref, &dref->node, bytenr,
+			     num_bytes, parent, ref_root, owner, offset,
+			     action);
+}
+
 /*
  * add a delayed data ref. it's similar to btrfs_add_delayed_tree_ref.
  */
@@ -870,14 +895,10 @@ int btrfs_add_delayed_data_ref(struct btrfs_fs_info *fs_info,
 	 * insert both the head node and the new ref without dropping
 	 * the spin lock
 	 */
-	head_ref = add_delayed_ref_head(fs_info, trans, head_ref, record,
-					bytenr, num_bytes, ref_root, reserved,
-					action, 1, 0, &qrecord_inserted,
-					old_ref_mod, new_ref_mod);
-
-	add_delayed_data_ref(fs_info, trans, head_ref, &ref->node, bytenr,
-				   num_bytes, parent, ref_root, owner, offset,
-				   action);
+	btrfs_add_delayed_data_ref_locked(fs_info, trans, ref, head_ref, record,
+			bytenr, num_bytes, parent, ref_root, owner, offset,
+			reserved, action, &qrecord_inserted, old_ref_mod,
+			new_ref_mod);
 	spin_unlock(&delayed_refs->lock);
 
 	if (qrecord_inserted)
diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h
index 7f00db50bd24..ad6c5dceea38 100644
--- a/fs/btrfs/delayed-ref.h
+++ b/fs/btrfs/delayed-ref.h
@@ -234,12 +234,22 @@ static inline void btrfs_put_delayed_ref_head(struct btrfs_delayed_ref_head *hea
 		kmem_cache_free(btrfs_delayed_ref_head_cachep, head);
 }
 
+struct btrfs_qgroup_extent_record;
 int btrfs_add_delayed_tree_ref(struct btrfs_fs_info *fs_info,
 			       struct btrfs_trans_handle *trans,
 			       u64 bytenr, u64 num_bytes, u64 parent,
 			       u64 ref_root, int level, int action,
 			       struct btrfs_delayed_extent_op *extent_op,
 			       int *old_ref_mod, int *new_ref_mod);
+void btrfs_add_delayed_data_ref_locked(struct btrfs_fs_info *fs_info,
+			struct btrfs_trans_handle *trans,
+			struct btrfs_delayed_data_ref *dref,
+			struct btrfs_delayed_ref_head *head_ref,
+			struct btrfs_qgroup_extent_record *qrecord,
+			u64 bytenr, u64 num_bytes, u64 parent, u64 ref_root,
+			u64 owner, u64 offset, u64 reserved, int action,
+			int *qrecord_inserted_ret, int *old_ref_mod,
+			int *new_ref_mod);
 int btrfs_add_delayed_data_ref(struct btrfs_fs_info *fs_info,
 			       struct btrfs_trans_handle *trans,
 			       u64 bytenr, u64 num_bytes,
-- 
2.17.0




  parent reply	other threads:[~2018-05-15  8:52 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-15  8:51 [PATCH v14.6 00/14] Btrfs In-band De-duplication Lu Fengqi
2018-05-15  8:51 ` [PATCH v14.6 01/14] btrfs: introduce type based delalloc metadata reserve Lu Fengqi
2018-05-15  8:51 ` [PATCH v14.6 02/14] btrfs: Introduce COMPRESS reserve type to fix false enospc for compression Lu Fengqi
2018-05-15  8:51 ` [PATCH v14.6 03/14] btrfs: dedupe: Introduce dedupe framework and its header Lu Fengqi
2018-05-15  8:51 ` [PATCH v14.6 04/14] btrfs: dedupe: Introduce function to initialize dedupe info Lu Fengqi
2018-05-17  5:49   ` [PATCH v14.7 " Lu Fengqi
2018-05-15  8:51 ` [PATCH v14.6 05/14] btrfs: dedupe: Introduce function to add hash into in-memory tree Lu Fengqi
2018-05-15  8:51 ` [PATCH v14.6 06/14] btrfs: dedupe: Introduce function to remove hash from " Lu Fengqi
2018-05-15  8:51 ` Lu Fengqi [this message]
2018-05-15  8:51 ` [PATCH v14.6 08/14] btrfs: dedupe: Introduce function to search for an existing hash Lu Fengqi
2018-05-15  8:51 ` [PATCH v14.6 09/14] btrfs: dedupe: Implement btrfs_dedupe_calc_hash interface Lu Fengqi
2018-05-17  5:51   ` [PATCH v14.7 " Lu Fengqi
2018-05-15  8:51 ` [PATCH v14.6 10/14] btrfs: ordered-extent: Add support for dedupe Lu Fengqi
2018-05-15  8:52 ` [PATCH v14.6 11/14] btrfs: dedupe: Inband in-memory only de-duplication implement Lu Fengqi
2018-05-15  8:52 ` [PATCH v14.6 12/14] btrfs: dedupe: Add ioctl for inband deduplication Lu Fengqi
2018-05-15  8:52 ` [PATCH v14.6 13/14] btrfs: relocation: Enhance error handling to avoid BUG_ON Lu Fengqi
2018-05-15  8:52 ` [PATCH v14.6 14/14] btrfs: dedupe: Introduce new reconfigure ioctl Lu Fengqi

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=20180515085203.17470-8-lufq.fnst@cn.fujitsu.com \
    --to=lufq.fnst@cn.fujitsu.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=quwenruo@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.