[Devel] [PATCH RHEL9 COMMIT] dm_qcow2: Kill nr_images and introduce img_id instead

Konstantin Khorenko khorenko at virtuozzo.com
Tue Dec 7 17:44:58 MSK 2021


The commit is pushed to "branch-rh9-5.14.vz9.1.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh9-5.14.0-4.vz9.10.33
------>
commit 7a6e5ec39fe685b562be81b05117605d9dddbd48
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date:   Tue Dec 7 17:44:58 2021 +0300

    dm_qcow2: Kill nr_images and introduce img_id instead
    
    tgt->nr_images is not stable in relation to qcow2_img_inc(),
    so we kill it. Instead of that, we will use img_id
    in every qcow2.
    
    Feature: dm-qcow2: block device over QCOW2 file driver
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 drivers/md/dm-qcow2-cmd.c    | 3 +--
 drivers/md/dm-qcow2-target.c | 7 +++----
 drivers/md/dm-qcow2.h        | 3 +--
 3 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/md/dm-qcow2-cmd.c b/drivers/md/dm-qcow2-cmd.c
index 2f1df95e219b..21316eec893a 100644
--- a/drivers/md/dm-qcow2-cmd.c
+++ b/drivers/md/dm-qcow2-cmd.c
@@ -208,7 +208,6 @@ static int qcow2_merge_backward(struct qcow2_target *tgt)
 			pr_err("dm-qcow2: Can't unuse lower (%d)\n", ret2);
 		goto out;
 	}
-	tgt->nr_images--;
 	tgt->top = lower;
 	smp_wmb(); /* Pairs with qcow2_ref_inc() */
 	qcow2_inflight_ref_switch(tgt); /* Pending qios */
@@ -230,7 +229,7 @@ static struct qcow2 *qcow2_get_img(struct qcow2_target *tgt, u32 img_id)
 
 	lockdep_assert_held(&tgt->ctl_mutex); /* tgt->top */
 
-	skip = tgt->nr_images - 1 - img_id;
+	skip = qcow2->img_id - img_id;
 	while (qcow2 && skip > 0) {
 		qcow2 = qcow2->lower;
 		skip--;
diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
index 97845929b6b5..d7ecd79f3376 100644
--- a/drivers/md/dm-qcow2-target.c
+++ b/drivers/md/dm-qcow2-target.c
@@ -700,7 +700,7 @@ static int qcow2_parse_header(struct dm_target *ti, struct qcow2 *qcow2,
 
 static int qcow2_parse_metadata(struct dm_target *ti, struct qcow2_target *tgt)
 {
-	unsigned int i, nr_images = tgt->nr_images;
+	unsigned int i, nr_images = tgt->top->img_id + 1;
 	struct qcow2 *qcow2, *upper = NULL;
 	int ret;
 
@@ -753,6 +753,7 @@ static int qcow2_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 			ret = PTR_ERR(qcow2);
 			goto err;
 		}
+		qcow2->img_id = i;
 
 		ret = qcow2_attach_file(ti, tgt, qcow2, fd);
 		if (ret) {
@@ -763,8 +764,6 @@ static int qcow2_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 		upper = qcow2;
 	}
 
-	tgt->nr_images = argc;
-
 	ret = qcow2_parse_metadata(ti, tgt);
 	if (ret)
 		goto err;
@@ -849,7 +848,7 @@ static void qcow2_status(struct dm_target *ti, status_type_t type,
 		result[0] = '\0';
 		break;
 	case STATUSTYPE_TABLE:
-		DMEMIT("%u v%u %llu", tgt->nr_images, hdr->version,
+		DMEMIT("%u v%u %llu", qcow2->img_id + 1, hdr->version,
 				      to_sector(qcow2->clu_size));
 		break;
 	}
diff --git a/drivers/md/dm-qcow2.h b/drivers/md/dm-qcow2.h
index 0dc65f43df9e..3cb28c459605 100644
--- a/drivers/md/dm-qcow2.h
+++ b/drivers/md/dm-qcow2.h
@@ -122,8 +122,6 @@ struct qcow2_target {
 	bool md_writeback_error;
 	bool truncate_error;
 
-	unsigned int nr_images;
-
 	atomic_t service_qios;
 	struct wait_queue_head service_wq;
 
@@ -160,6 +158,7 @@ struct qcow2 {
 	/* Position to search next unused cluster */
 	loff_t free_cluster_search_pos;
 
+	u32 img_id;
 	struct qcow2 *lower; /* Lower delta (backing file) */
 
 	struct rb_root md_pages; /* Metadata pages */


More information about the Devel mailing list