[Devel] [PATCH RH9 08/12] dm-qcow2: Extend alloc_and_insert_md_page() with @qio argument

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


Move linking to wait_list into this function.
This removes excess lock/unlock.

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

diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index a9a839dd189a..e3444b6b90bd 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -1526,14 +1526,10 @@ static int submit_read_md_page(struct qcow2 *qcow2, struct qio **qio,
 	lockdep_assert_held(&qcow2->md_pages_lock);
 	spin_unlock_irq(&qcow2->md_pages_lock);
 
-	ret = alloc_and_insert_md_page(qcow2, page_id, &md);
+	ret = alloc_and_insert_md_page(qcow2, page_id, &md, *qio);
 	if (ret < 0)
 		goto out_lock;
-
-	spin_lock_irq(&qcow2->md_pages_lock);
-	list_add_tail(&(*qio)->link, &md->wait_list);
 	*qio = NULL;
-	spin_unlock_irq(&qcow2->md_pages_lock);
 
 	submit_rw_md_page(READ, qcow2, md);
 out_lock:
@@ -2007,7 +2003,7 @@ static int place_r2(struct qcow2 *qcow2, struct qcow2_map_item *r1,
 		return ret;
 	}
 
-	ret = alloc_and_insert_md_page(qcow2, page_id, &r2->md);
+	ret = alloc_and_insert_md_page(qcow2, page_id, &r2->md, NULL);
 	if (ret < 0) {
 		pr_err("Can't alloc: ret=%d, page_id=%llu\n", ret, page_id);
 		return -EIO;
@@ -2255,7 +2251,7 @@ static int relocate_refcount_table(struct qcow2 *qcow2, struct qio **qio)
 
 	/* Alloc R1/R2 pages covering clusters of new R1 and new R2 */
 	for (i = pos + (u64)old_clus * clu_size; i < r2_end; i += PAGE_SIZE) {
-		ret = alloc_and_insert_md_page(qcow2, i >> PAGE_SHIFT, &md);
+		ret = alloc_and_insert_md_page(qcow2, i >> PAGE_SHIFT, &md, NULL);
 		if (ret < 0)
 			goto err_free_r2_pages;
 		spin_lock_irq(&qcow2->md_pages_lock);
diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
index d57e944aa5bd..98cdc98bcdeb 100644
--- a/drivers/md/dm-qcow2-target.c
+++ b/drivers/md/dm-qcow2-target.c
@@ -367,7 +367,9 @@ void zero_fill_page_from(struct page *page, unsigned int from)
 	kunmap_atomic(addr);
 }
 
-int alloc_and_insert_md_page(struct qcow2 *qcow2, u64 index, struct md_page **md)
+/* @qio to link into wait_list or NULL */
+int alloc_and_insert_md_page(struct qcow2 *qcow2, u64 index,
+			     struct md_page **md, struct qio *qio)
 {
 	int ret = -ENOMEM;
 
@@ -390,6 +392,8 @@ int alloc_and_insert_md_page(struct qcow2 *qcow2, u64 index, struct md_page **md
 
 	spin_lock_irq(&qcow2->md_pages_lock);
 	ret = md_page_try_insert(qcow2, *md);
+	if (!ret && qio)
+		list_add_tail(&qio->link, &(*md)->wait_list);
 	spin_unlock_irq(&qcow2->md_pages_lock);
 	if (ret)
 		goto err_putpage;
@@ -675,7 +679,7 @@ static int qcow2_parse_header(struct dm_target *ti, struct qcow2 *qcow2,
 	}
 	qcow2->file_preallocated_area_start = qcow2->file_size;
 
-	ret = alloc_and_insert_md_page(qcow2, 0, &md);
+	ret = alloc_and_insert_md_page(qcow2, 0, &md, NULL);
 	if (ret)
 		return ret;
 	ret = rw_page_sync(READ, qcow2, md->id, md->page);
diff --git a/drivers/md/dm-qcow2.h b/drivers/md/dm-qcow2.h
index 60cb370dcbab..cff61eec4c93 100644
--- a/drivers/md/dm-qcow2.h
+++ b/drivers/md/dm-qcow2.h
@@ -281,7 +281,7 @@ int qcow2_clone_and_map(struct dm_target *ti, struct request *rq,
 
 void do_qcow2_work(struct work_struct *ws);
 void do_qcow2_fsync_work(struct work_struct *ws);
-int alloc_and_insert_md_page(struct qcow2 *qcow2, u64 index, struct md_page **md);
+int alloc_and_insert_md_page(struct qcow2 *qcow2, u64 index, struct md_page **md, struct qio *qio);
 struct md_page *md_page_find_or_postpone(struct qcow2 *qcow2, unsigned int id, struct qio **qio);
 struct md_page *md_page_renumber(struct qcow2 *qcow2, unsigned int id, unsigned int new_id);
 void md_page_erase(struct qcow2 *qcow2, struct md_page *md);




More information about the Devel mailing list