OpenVZ / Virtuozzo kernel development (devel@openvz.org)
 help / color / mirror / Atom feed
* [Devel] [PATCH hci-8.2 v2] dm-qcow2: use BLK_OPEN_* flags to test dm_table_get_mode()
@ 2026-11-21  8:37 Alexander Ivanov
  2026-11-21  8:40 ` no-reply
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Alexander Ivanov @ 2026-11-21  8:37 UTC (permalink / raw)
  To: andrey.zhadchenko; +Cc: devel

dm_table_get_mode() returns blk_mode_t, but qcow2_attach_file(),
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 only reader of is_ro in qcow2_check_convert_hdr() is a
commented-out check that refused a writable image whose dirty bit
disagrees with the kernel_sets_dirty_bit parameter. Remove is_ro along
with that check, and drop the ti argument, which is_ro was the only
user of.

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>
---
v2:
- rebase on hci-dev, drop the qcow2_truncate_unused_tail() hunk
- use the dm-qcow2: subject prefix, shorten the subject
- drop the now unused ti argument of qcow2_check_convert_hdr()
- describe the removed commented-out check

 drivers/md/dm-qcow2-target.c | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)

diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
index d445bfe1232a..c00e4ef10d53 100644
--- a/drivers/md/dm-qcow2-target.c
+++ b/drivers/md/dm-qcow2-target.c
@@ -563,12 +563,11 @@ static struct qcow2_target *alloc_qcow2_target(struct dm_target *ti)
 	return NULL;
 }
 
-static int qcow2_check_convert_hdr(struct dm_target *ti,
-				   struct QCowHeader *raw_hdr,
+static int qcow2_check_convert_hdr(struct QCowHeader *raw_hdr,
 				   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);
@@ -619,11 +618,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))
@@ -742,7 +736,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 */
@@ -761,9 +755,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;
 	}
@@ -920,7 +914,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(ti, raw_hdr, hdr, min_len, max_len);
+	ret = qcow2_check_convert_hdr(raw_hdr, hdr, min_len, max_len);
 	raw_autoclear = be64_to_cpu(raw_hdr->autoclear_features);
 	kunmap(md->page);
 	if (ret < 0)
@@ -1184,7 +1178,7 @@ static void qcow2_postsuspend(struct dm_target *ti)
 	noio_flag = memalloc_noio_save();
 	qcow2_flush_deferred_activity_all(tgt);
 
-	if (dm_table_get_mode(ti->table) & FMODE_WRITE) {
+	if (dm_table_get_mode(ti->table) & BLK_OPEN_WRITE) {
 		if (qcow2_truncate_unused_tail(tgt, qcow2))
 			tgt->truncate_error = true;
 		ret = qcow2_set_image_file_features(qcow2, false);
@@ -1217,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] 5+ messages in thread

* Re: [Devel] [PATCH hci-8.2 v2] dm-qcow2: use BLK_OPEN_* flags to test dm_table_get_mode()
  2026-11-21  8:37 [Devel] [PATCH hci-8.2 v2] dm-qcow2: use BLK_OPEN_* flags to test dm_table_get_mode() Alexander Ivanov
@ 2026-11-21  8:40 ` no-reply
  2026-11-24 23:57 ` Andrey Zhadchenko
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: no-reply @ 2026-11-21  8:40 UTC (permalink / raw)
  To: Alexander Ivanov, andrey.zhadchenko; +Cc: devel

> dm_table_get_mode() returns blk_mode_t, but qcow2_attach_file(),
> 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 only reader of is_ro in qcow2_check_convert_hdr() is a
> commented-out check that refused a writable image whose dirty bit
> disagrees with the kernel_sets_dirty_bit parameter. Remove is_ro along
> with that check, and drop the ti argument, which is_ro was the only
> user of.
> 
> 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/20261121083700.4002573-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] 5+ messages in thread

* Re: [Devel] [PATCH hci-8.2 v2] dm-qcow2: use BLK_OPEN_* flags to test dm_table_get_mode()
  2026-11-21  8:37 [Devel] [PATCH hci-8.2 v2] dm-qcow2: use BLK_OPEN_* flags to test dm_table_get_mode() Alexander Ivanov
  2026-11-21  8:40 ` no-reply
@ 2026-11-24 23:57 ` Andrey Zhadchenko
  2026-11-30 13:17 ` Konstantin Khorenko
  2026-11-30 13:18 ` Konstantin Khorenko
  3 siblings, 0 replies; 5+ messages in thread
From: Andrey Zhadchenko @ 2026-11-24 23:57 UTC (permalink / raw)
  To: Alexander Ivanov; +Cc: devel

Reviewed-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>

On 11/21/26 09:37, Alexander Ivanov wrote:
> dm_table_get_mode() returns blk_mode_t, but qcow2_attach_file(),
> 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 only reader of is_ro in qcow2_check_convert_hdr() is a
> commented-out check that refused a writable image whose dirty bit
> disagrees with the kernel_sets_dirty_bit parameter. Remove is_ro along
> with that check, and drop the ti argument, which is_ro was the only
> user of.
> 
> 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>
> ---
> v2:
> - rebase on hci-dev, drop the qcow2_truncate_unused_tail() hunk
> - use the dm-qcow2: subject prefix, shorten the subject
> - drop the now unused ti argument of qcow2_check_convert_hdr()
> - describe the removed commented-out check
> 
>   drivers/md/dm-qcow2-target.c | 24 +++++++++---------------
>   1 file changed, 9 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
> index d445bfe1232a..c00e4ef10d53 100644
> --- a/drivers/md/dm-qcow2-target.c
> +++ b/drivers/md/dm-qcow2-target.c
> @@ -563,12 +563,11 @@ static struct qcow2_target *alloc_qcow2_target(struct dm_target *ti)
>   	return NULL;
>   }
>   
> -static int qcow2_check_convert_hdr(struct dm_target *ti,
> -				   struct QCowHeader *raw_hdr,
> +static int qcow2_check_convert_hdr(struct QCowHeader *raw_hdr,
>   				   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);
> @@ -619,11 +618,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))
> @@ -742,7 +736,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 */
> @@ -761,9 +755,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;
>   	}
> @@ -920,7 +914,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(ti, raw_hdr, hdr, min_len, max_len);
> +	ret = qcow2_check_convert_hdr(raw_hdr, hdr, min_len, max_len);
>   	raw_autoclear = be64_to_cpu(raw_hdr->autoclear_features);
>   	kunmap(md->page);
>   	if (ret < 0)
> @@ -1184,7 +1178,7 @@ static void qcow2_postsuspend(struct dm_target *ti)
>   	noio_flag = memalloc_noio_save();
>   	qcow2_flush_deferred_activity_all(tgt);
>   
> -	if (dm_table_get_mode(ti->table) & FMODE_WRITE) {
> +	if (dm_table_get_mode(ti->table) & BLK_OPEN_WRITE) {
>   		if (qcow2_truncate_unused_tail(tgt, qcow2))
>   			tgt->truncate_error = true;
>   		ret = qcow2_set_image_file_features(qcow2, false);
> @@ -1217,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");

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

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

* Re: [Devel] [PATCH hci-8.2 v2] dm-qcow2: use BLK_OPEN_* flags to test dm_table_get_mode()
  2026-11-21  8:37 [Devel] [PATCH hci-8.2 v2] dm-qcow2: use BLK_OPEN_* flags to test dm_table_get_mode() Alexander Ivanov
  2026-11-21  8:40 ` no-reply
  2026-11-24 23:57 ` Andrey Zhadchenko
@ 2026-11-30 13:17 ` Konstantin Khorenko
  2026-11-30 13:18 ` Konstantin Khorenko
  3 siblings, 0 replies; 5+ messages in thread
From: Konstantin Khorenko @ 2026-11-30 13:17 UTC (permalink / raw)
  To: Alexander Ivanov; +Cc: devel

Applying with this fix on my side:
- the message names 6e1526bb6ed59 ("dm-qcow2: Temporary disable dirty
  bit check") as the commit that commented the dirty bit check out.

The rest of the v1 items are done, thanks: rebased on hci-8.2, ti
dropped, dm-qcow2: prefix.

On Sat, 21 Nov 2026 09:37:00 +0100, Alexander Ivanov wrote:
> The only reader of is_ro in qcow2_check_convert_hdr() is a
> commented-out check that refused a writable image whose dirty bit
> disagrees with the kernel_sets_dirty_bit parameter. Remove is_ro along

The paragraph as applied:

  The only reader of is_ro in qcow2_check_convert_hdr() is the check that
  refused a writable image whose dirty bit disagrees with the
  kernel_sets_dirty_bit parameter, commented out by 6e1526bb6ed59
  ("dm-qcow2: Temporary disable dirty bit check"). Remove is_ro along
  with that check, and drop the ti argument, which is_ro was the only
  user of.

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

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

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

* Re: [Devel] [PATCH hci-8.2 v2] dm-qcow2: use BLK_OPEN_* flags to test dm_table_get_mode()
  2026-11-21  8:37 [Devel] [PATCH hci-8.2 v2] dm-qcow2: use BLK_OPEN_* flags to test dm_table_get_mode() Alexander Ivanov
                   ` (2 preceding siblings ...)
  2026-11-30 13:17 ` Konstantin Khorenko
@ 2026-11-30 13:18 ` Konstantin Khorenko
  3 siblings, 0 replies; 5+ messages in thread
From: Konstantin Khorenko @ 2026-11-30 13:18 UTC (permalink / raw)
  To: andrey.zhadchenko, Alexander Ivanov; +Cc: devel

On Sat, 21 Nov 2026 09:37:00 +0100, Alexander Ivanov wrote:
> dm-qcow2: use BLK_OPEN_* flags to test dm_table_get_mode()

Applied to branch-rh10-6.12.0-211.75.1.26.x.vz10-ovz, will be released in rh10-6.12.0-211.75.1.26.6.vz10, thanks!

[1/1] dm-qcow2: use BLK_OPEN_* flags to test dm_table_get_mode()
      https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/0fad9f1d12f2

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team


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

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

end of thread, other threads:[~2026-11-30 13:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-21  8:37 [Devel] [PATCH hci-8.2 v2] dm-qcow2: use BLK_OPEN_* flags to test dm_table_get_mode() Alexander Ivanov
2026-11-21  8:40 ` no-reply
2026-11-24 23:57 ` Andrey Zhadchenko
2026-11-30 13:17 ` Konstantin Khorenko
2026-11-30 13:18 ` Konstantin Khorenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox