[Devel] [PATCH RH9 07/12] dm-qcow2: Introduce __handle_md_page()

Kirill Tkhai ktkhai at virtuozzo.com
Wed Jan 19 19:17:31 MSK 2022


Extract all the code from handle_md_page() except locking.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 drivers/md/dm-qcow2-map.c    |   27 ++++++++++++++++++++++-----
 drivers/md/dm-qcow2-target.c |    3 +--
 2 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index 6da6339f1213..a9a839dd189a 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -1523,17 +1523,22 @@ static int submit_read_md_page(struct qcow2 *qcow2, struct qio **qio,
 	struct md_page *md;
 	int ret;
 
+	lockdep_assert_held(&qcow2->md_pages_lock);
+	spin_unlock_irq(&qcow2->md_pages_lock);
+
 	ret = alloc_and_insert_md_page(qcow2, page_id, &md);
 	if (ret < 0)
-		return ret;
+		goto out_lock;
 
 	spin_lock_irq(&qcow2->md_pages_lock);
 	list_add_tail(&(*qio)->link, &md->wait_list);
-	spin_unlock_irq(&qcow2->md_pages_lock);
 	*qio = NULL;
+	spin_unlock_irq(&qcow2->md_pages_lock);
 
 	submit_rw_md_page(READ, qcow2, md);
-	return 0;
+out_lock:
+	spin_lock_irq(&qcow2->md_pages_lock);
+	return ret;
 }
 
 /*
@@ -1541,11 +1546,12 @@ static int submit_read_md_page(struct qcow2 *qcow2, struct qio **qio,
  * interesting in searching cached in memory md only.
  * This is aimed to be called not only from main kwork.
  */
-static int handle_md_page(struct qcow2 *qcow2, u64 page_id,
-		 struct qio **qio, struct md_page **ret_md)
+static int __handle_md_page(struct qcow2 *qcow2, u64 page_id,
+			    struct qio **qio, struct md_page **ret_md)
 {
 	struct md_page *md;
 
+	lockdep_assert_held(&qcow2->md_pages_lock);
 	md = md_page_find_or_postpone(qcow2, page_id, qio);
 	if (!md) {
 		if (qio && *qio)
@@ -1557,6 +1563,17 @@ static int handle_md_page(struct qcow2 *qcow2, u64 page_id,
 	return 1;
 }
 
+static int handle_md_page(struct qcow2 *qcow2, u64 page_id,
+		 struct qio **qio, struct md_page **ret_md)
+{
+	int ret;
+
+	spin_lock_irq(&qcow2->md_pages_lock);
+	ret = __handle_md_page(qcow2, page_id, qio, ret_md);
+	spin_unlock_irq(&qcow2->md_pages_lock);
+	return ret;
+}
+
 static u32 qio_subclus_covered_start_size(struct qcow2 *qcow2,
 					  struct qio *qio,
 					  u32 subclus_mask)
diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
index 9e82189312e3..d57e944aa5bd 100644
--- a/drivers/md/dm-qcow2-target.c
+++ b/drivers/md/dm-qcow2-target.c
@@ -296,7 +296,7 @@ struct md_page *md_page_find_or_postpone(struct qcow2 *qcow2, unsigned int id,
 {
 	struct md_page *md;
 
-	spin_lock_irq(&qcow2->md_pages_lock);
+	lockdep_assert_held(&qcow2->md_pages_lock);
 	md = __md_page_find(qcow2, id);
 	if (md && !(md->status & MD_UPTODATE)) {
 		if (qio) {
@@ -305,7 +305,6 @@ struct md_page *md_page_find_or_postpone(struct qcow2 *qcow2, unsigned int id,
 		}
 		md = NULL;
 	}
-	spin_unlock_irq(&qcow2->md_pages_lock);
 
 	return md;
 }




More information about the Devel mailing list