[Devel] [PATCH RHEL9 COMMIT] dm-qcow2: Introduce __handle_md_page()

Konstantin Khorenko khorenko at virtuozzo.com
Thu Mar 24 00:23:59 MSK 2022


The commit is pushed to "branch-rh9-5.14.0-42.vz9.14.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh9-5.14.0-42.vz9.14.4
------>
commit 872a74e2223a312520ee0b9d7a7892cb57437cf0
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date:   Thu Mar 24 00:23:59 2022 +0300

    dm-qcow2: Introduce __handle_md_page()
    
    Extract all the code from handle_md_page() except locking.
    
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
    Feature: dm-qcow2: block device over QCOW2 files driver
---
 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 0bfcd5716908..49cd4db6f6d2 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -1525,17 +1525,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;
 }
 
 /*
@@ -1543,11 +1548,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)
@@ -1559,6 +1565,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 795d64516507..b0421988ddc8 100644
--- a/drivers/md/dm-qcow2-target.c
+++ b/drivers/md/dm-qcow2-target.c
@@ -304,7 +304,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) {
@@ -313,7 +313,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