[Devel] [PATCH RH9 3/5] dm_qcow2: Kill nr_images and introduce img_id instead

Kirill Tkhai ktkhai at virtuozzo.com
Thu Nov 25 19:05:47 MSK 2021


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.

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