All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
* [Devel] [PATCH hci-8.2] drivers/md/dm-qcow2: test the table mode against BLK_OPEN_WRITE, drop unused is_ro
@ 2026-11-20 16:40 Alexander Ivanov
  2026-11-20 16:42 ` no-reply
  2026-11-20 17:08 ` Konstantin Khorenko
  0 siblings, 2 replies; 3+ messages in thread
From: Alexander Ivanov @ 2026-11-20 16:40 UTC (permalink / raw)
  To: andrey.zhadchenko; +Cc: devel

dm_table_get_mode() returns blk_mode_t, but qcow2_check_convert_hdr(),
qcow2_attach_file(), qcow2_truncate_unused_tail(), qcow2_postsuspend()
and qcow2_preresume() still test its result against FMODE_WRITE. The
two flags have the same value today, so behaviour is unaffected. But it
is the wrong type, and it is inconsistent with the rest of the driver,
which already uses BLK_OPEN_WRITE.

Switch these checks to BLK_OPEN_WRITE. In qcow2_attach_file() test the
read and write bits of the table mode against the file mode one by one
instead of masking an fmode_t with a blk_mode_t.

The is_ro variable in qcow2_check_convert_hdr() has only a
commented-out user. Remove it along with the dead code.

https://virtuozzo.atlassian.net/browse/VSTOR-152395
Feature: dm-qcow2: block device over QCOW2 files driver

Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
---
 drivers/md/dm-qcow2-target.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
index 4cd5f2c0ed36..29b7f91a2919 100644
--- a/drivers/md/dm-qcow2-target.c
+++ b/drivers/md/dm-qcow2-target.c
@@ -565,7 +565,7 @@ static int qcow2_check_convert_hdr(struct dm_target *ti,
 				   struct QCowHeader *hdr,
 				   u64 min_len, u64 max_len)
 {
-	bool ext_l2, is_ro;
+	bool ext_l2;
 	u32 clu_size;
 
 	hdr->magic = cpu_to_be32(raw_hdr->magic);
@@ -616,11 +616,6 @@ static int qcow2_check_convert_hdr(struct dm_target *ti,
 	if (hdr->header_length < offsetof(struct QCowHeader, compression_type))
 		return -EINVAL;
 
-	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 &
 	    ~(INCOMPATIBLE_FEATURES_EXTL2_BIT|INCOMPATIBLE_FEATURES_DIRTY_BIT|
 	      INCOMPATIBLE_FEATURES_COMPRESSION))
@@ -739,7 +734,7 @@ static int qcow2_attach_file(struct dm_target *ti, struct qcow2_target *tgt,
 			     struct qcow2 *qcow2, int fd)
 {
 	struct file *file;
-	fmode_t mode;
+	blk_mode_t mode;
 
 	file = qcow2->file = fget(fd);
 	/* In case of further errors, cleanup is made by caller */
@@ -758,9 +753,9 @@ static int qcow2_attach_file(struct dm_target *ti, struct qcow2_target *tgt,
 		return -EINVAL;
 	}
 
-	mode = tgt->top != qcow2 ? FMODE_READ : dm_table_get_mode(ti->table);
-	mode &= (FMODE_READ|FMODE_WRITE);
-	if (mode & ~(file->f_mode & (FMODE_READ|FMODE_WRITE))) {
+	mode = tgt->top != qcow2 ? BLK_OPEN_READ : dm_table_get_mode(ti->table);
+	if (((mode & BLK_OPEN_READ) && !(file->f_mode & FMODE_READ)) ||
+	    ((mode & BLK_OPEN_WRITE) && !(file->f_mode & FMODE_WRITE))) {
 		ti->error = "Image file is opened in a wrong mode";
 		return -EACCES;
 	}
@@ -1079,7 +1074,7 @@ static void qcow2_truncate_unused_tail(struct dm_target *ti)
 	loff_t used_end, end = qcow2->file_preallocated_area_start;
 	int ret;
 
-	if (!(dm_table_get_mode(ti->table) & FMODE_WRITE))
+	if (!(dm_table_get_mode(ti->table) & BLK_OPEN_WRITE))
 		return;
 
 	if (tgt->md_writeback_error) {
@@ -1185,7 +1180,7 @@ static void qcow2_postsuspend(struct dm_target *ti)
 	qcow2_flush_deferred_activity_all(to_qcow2_target(ti));
 	qcow2_truncate_unused_tail(ti);
 
-	if (dm_table_get_mode(ti->table) & FMODE_WRITE) {
+	if (dm_table_get_mode(ti->table) & BLK_OPEN_WRITE) {
 		ret = qcow2_set_image_file_features(qcow2, false);
 		if (ret)
 			QC_ERR(ti, "Can't set features");
@@ -1216,7 +1211,7 @@ static int qcow2_preresume(struct dm_target *ti)
 	 * Despite .preresume has no undo, our target is singleton,
 	 * so we can set features uncoditionally here.
 	 */
-	if (dm_table_get_mode(ti->table) & FMODE_WRITE) {
+	if (dm_table_get_mode(ti->table) & BLK_OPEN_WRITE) {
 		ret = qcow2_set_image_file_features(tgt->top, true);
 		if (ret)
 			QC_ERR(ti, "Can't set features");
-- 
2.53.0

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Devel] [PATCH hci-8.2] drivers/md/dm-qcow2: test the table mode against BLK_OPEN_WRITE, drop unused is_ro
  2026-11-20 16:40 [Devel] [PATCH hci-8.2] drivers/md/dm-qcow2: test the table mode against BLK_OPEN_WRITE, drop unused is_ro Alexander Ivanov
@ 2026-11-20 16:42 ` no-reply
  2026-11-20 17:08 ` Konstantin Khorenko
  1 sibling, 0 replies; 3+ messages in thread
From: no-reply @ 2026-11-20 16:42 UTC (permalink / raw)
  To: Alexander Ivanov, andrey.zhadchenko; +Cc: devel

> dm_table_get_mode() returns blk_mode_t, but qcow2_check_convert_hdr(),
> qcow2_attach_file(), qcow2_truncate_unused_tail(), qcow2_postsuspend()
> and qcow2_preresume() still test its result against FMODE_WRITE. The
> two flags have the same value today, so behaviour is unaffected. But it
> is the wrong type, and it is inconsistent with the rest of the driver,
> which already uses BLK_OPEN_WRITE.
> 
> Switch these checks to BLK_OPEN_WRITE. In qcow2_attach_file() test the
> read and write bits of the table mode against the file mode one by one
> instead of masking an fmode_t with a blk_mode_t.
> 
> The is_ro variable in qcow2_check_convert_hdr() has only a
> commented-out user. Remove it along with the dead code.
> 
> https://virtuozzo.atlassian.net/browse/VSTOR-152395
> Feature: dm-qcow2: block device over QCOW2 files driver
> 
> Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>

Sashiko has reviewed this patch and found no issues.

Carry the trailer below into the next revision and Sashiko will not review this patch again.

Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261120164000.3954787-1-alexander.ivanov@virtuozzo.com?part=1


_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Devel] [PATCH hci-8.2] drivers/md/dm-qcow2: test the table mode against BLK_OPEN_WRITE, drop unused is_ro
  2026-11-20 16:40 [Devel] [PATCH hci-8.2] drivers/md/dm-qcow2: test the table mode against BLK_OPEN_WRITE, drop unused is_ro Alexander Ivanov
  2026-11-20 16:42 ` no-reply
@ 2026-11-20 17:08 ` Konstantin Khorenko
  1 sibling, 0 replies; 3+ messages in thread
From: Konstantin Khorenko @ 2026-11-20 17:08 UTC (permalink / raw)
  To: Alexander Ivanov; +Cc: devel

I won't apply this version, please send v2 with the changes below.

- Rebase on hci-8.2: drop the qcow2_truncate_unused_tail() hunk, redo
  the qcow2_postsuspend() hunk, take that function out of the list in
  the message.
- Drop the ti argument of qcow2_check_convert_hdr(), is_ro was its
  only user.
- Say in the message what the removed comment is.
- Use the "dm-qcow2:" prefix, the subject is 82 columns now.

The code is fine: every converted test checks the same bits as before.

On Fri, 20 Nov 2026 17:40:00 +0100, Alexander Ivanov wrote:
> dm_table_get_mode() returns blk_mode_t, but qcow2_check_convert_hdr(),
> qcow2_attach_file(), qcow2_truncate_unused_tail(), qcow2_postsuspend()
> and qcow2_preresume() still test its result against FMODE_WRITE.

fa6cf94f94fa6 ("dm-qcow2: truncate the unused tail of an image after
backward merge") is in hci-8.2 now. It took the mode test out of
qcow2_truncate_unused_tail() and calls it inside the FMODE_WRITE block
of qcow2_postsuspend(), so this patch does not apply there. Four sites
are left.

> The is_ro variable in qcow2_check_convert_hdr() has only a
> commented-out user. Remove it along with the dead code.

That is the dirty bit check disabled by 6e1526bb6ed59 ("dm-qcow2:
Temporary disable dirty bit check"), and kernel_sets_dirty_bit is
still a module parameter. Name the commit and say why the check is
not coming back, so nobody goes looking for it.

> -	bool ext_l2, is_ro;
> +	bool ext_l2;

With is_ro gone, nothing in qcow2_check_convert_hdr() uses ti, and
qcow2_parse_header() is its only caller. Drop the argument too.

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-20 17:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-20 16:40 [Devel] [PATCH hci-8.2] drivers/md/dm-qcow2: test the table mode against BLK_OPEN_WRITE, drop unused is_ro Alexander Ivanov
2026-11-20 16:42 ` no-reply
2026-11-20 17:08 ` Konstantin Khorenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.