[Devel] [PATCH RHEL9 COMMIT] dm-qcow2: Do not check for dirty bit if mount is RO

Konstantin Khorenko khorenko at virtuozzo.com
Fri Nov 12 15:34:48 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.25
------>
commit 7496f6be4c6fd287385c2b0006ca134bd484105d
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date:   Fri Nov 12 15:34:48 2021 +0300

    dm-qcow2: Do not check for dirty bit if mount is RO
    
    In case of RO mount, the image also may be RO or on RO mount,
    so there is no possibility to request dirty bit assignment
    from userspace.
    
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 drivers/md/dm-qcow2-target.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
index 2de817154ba3..c41f623fb7d7 100644
--- a/drivers/md/dm-qcow2-target.c
+++ b/drivers/md/dm-qcow2-target.c
@@ -451,12 +451,13 @@ static struct qcow2_target *alloc_qcow2_target(struct dm_target *ti)
 	return NULL;
 }
 
-static int qcow2_check_convert_hdr(struct QCowHeader *raw_hdr,
+static int qcow2_check_convert_hdr(struct dm_target *ti,
+				   struct QCowHeader *raw_hdr,
 				   struct QCowHeader *hdr,
 				   u64 min_len, u64 max_len)
 {
+	bool ext_l2, is_ro;
 	u32 clu_size;
-	bool ext_l2;
 
 	hdr->magic = cpu_to_be32(raw_hdr->magic);
 	hdr->version = be32_to_cpu(raw_hdr->version);
@@ -501,7 +502,9 @@ static int qcow2_check_convert_hdr(struct QCowHeader *raw_hdr,
 	hdr->refcount_order = be32_to_cpu(raw_hdr->refcount_order);
 	hdr->header_length = be32_to_cpu(raw_hdr->header_length);
 
-	if (kernel_sets_dirty_bit !=
+	is_ro = !(dm_table_get_mode(ti->table) & FMODE_WRITE);
+
+	if (!is_ro && kernel_sets_dirty_bit !=
 	    !(hdr->incompatible_features & INCOMPATIBLE_FEATURES_DIRTY_BIT))
 		return kernel_sets_dirty_bit ? -EUCLEAN : -ENOLCK;
 	if (hdr->incompatible_features &
@@ -555,10 +558,15 @@ int qcow2_set_image_file_features(struct qcow2 *qcow2, bool dirty)
 	u64 dirty_mask = cpu_to_be64(INCOMPATIBLE_FEATURES_DIRTY_BIT);
 	struct QCowHeader *raw_hdr;
 	struct md_page *md;
+	bool is_ro;
 
 	if (qcow2->hdr.version ==  2)
 		return 0;
 
+	is_ro = !(dm_table_get_mode(qcow2->tgt->ti->table) & FMODE_WRITE);
+	if (is_ro)
+		return 0;
+
 	md = md_page_find(qcow2, 0);
 	if (WARN_ON_ONCE(!md || !(md->status & MD_UPTODATE)))
 		return -EIO;
@@ -663,7 +671,7 @@ static int qcow2_parse_header(struct dm_target *ti, struct qcow2 *qcow2,
 		min_len = PAGE_SIZE;
 		max_len = upper->hdr.size;
 	}
-	ret = qcow2_check_convert_hdr(raw_hdr, hdr, min_len, max_len);
+	ret = qcow2_check_convert_hdr(ti, raw_hdr, hdr, min_len, max_len);
 	kunmap(md->page);
 	if (ret < 0)
 		goto out;


More information about the Devel mailing list