Linux Device Mapper development
 help / color / mirror / Atom feed
From: Milan Broz <gmazyland@gmail.com>
To: Mikulas Patocka <mpatocka@redhat.com>, Mike Snitzer <snitzer@kernel.org>
Cc: dm-devel@redhat.com
Subject: Re: [dm-devel] [PATCH] dm-zero: support discards
Date: Tue, 7 Mar 2023 09:35:30 +0100	[thread overview]
Message-ID: <11c8212f-e2be-013d-acf7-0402ef13cfac@gmail.com> (raw)
In-Reply-To: <alpine.LRH.2.21.2303061407210.5778@file01.intranet.prod.int.rdu2.redhat.com>

On 3/6/23 20:10, Mikulas Patocka wrote:
> This patch adds discard support to dm-zero. The discards are ignored.
> It is useful when the user combines dm-zero with other discard-supporting
> targets in the same table; without dm-zero support, discards would be
> disabled for the whole combined device.
> 
> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>

Tested-by: Milan Broz <gmazyland@gmail.com>

Just for the context: cryptsetup use dm-zero to mask certain areas
(in Bitlocker-compatible mapping) and discard flag disappeared in this situation
(discard is not supported configuration here, but it should work :)
Originally reported here https://gitlab.com/cryptsetup/cryptsetup/-/issues/718

Propagating discard support in dm-zero is definitely useful for other uses, though.

Thanks,
Milan

> 
> ---
>   drivers/md/dm-table.c |    9 ++++++++-
>   drivers/md/dm-zero.c  |    4 +++-
>   2 files changed, 11 insertions(+), 2 deletions(-)
> 
> Index: linux-2.6/drivers/md/dm-zero.c
> ===================================================================
> --- linux-2.6.orig/drivers/md/dm-zero.c
> +++ linux-2.6/drivers/md/dm-zero.c
> @@ -27,6 +27,7 @@ static int zero_ctr(struct dm_target *ti
>   	 * Silently drop discards, avoiding -EOPNOTSUPP.
>   	 */
>   	ti->num_discard_bios = 1;
> +	ti->discards_supported = true;
>   
>   	return 0;
>   }
> @@ -45,6 +46,7 @@ static int zero_map(struct dm_target *ti
>   		zero_fill_bio(bio);
>   		break;
>   	case REQ_OP_WRITE:
> +	case REQ_OP_DISCARD:
>   		/* writes get silently dropped */
>   		break;
>   	default:
> @@ -59,7 +61,7 @@ static int zero_map(struct dm_target *ti
>   
>   static struct target_type zero_target = {
>   	.name   = "zero",
> -	.version = {1, 1, 0},
> +	.version = {1, 2, 0},
>   	.features = DM_TARGET_NOWAIT,
>   	.module = THIS_MODULE,
>   	.ctr    = zero_ctr,
> Index: linux-2.6/drivers/md/dm-table.c
> ===================================================================
> --- linux-2.6.orig/drivers/md/dm-table.c
> +++ linux-2.6/drivers/md/dm-table.c
> @@ -1670,8 +1670,15 @@ int dm_calculate_queue_limits(struct dm_
>   
>   		blk_set_stacking_limits(&ti_limits);
>   
> -		if (!ti->type->iterate_devices)
> +		if (!ti->type->iterate_devices) {
> +			if (ti->discards_supported) {
> +				ti_limits.max_discard_sectors = UINT_MAX;
> +				ti_limits.max_hw_discard_sectors = UINT_MAX;
> +				ti_limits.discard_granularity = 512;
> +				ti_limits.discard_alignment = 0;
> +			}
>   			goto combine_limits;
> +		}
>   
>   		/*
>   		 * Combine queue limits of all the devices this target uses.
> 

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


  reply	other threads:[~2023-03-07  8:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-06 19:10 [dm-devel] [PATCH] dm-zero: support discards Mikulas Patocka
2023-03-07  8:35 ` Milan Broz [this message]
2023-03-07 17:32 ` [dm-devel] [PATCH v2] dm-zero, dm-error: " Mikulas Patocka
2023-03-10  9:05   ` Milan Broz
2023-03-30 10:35     ` Milan Broz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=11c8212f-e2be-013d-acf7-0402ef13cfac@gmail.com \
    --to=gmazyland@gmail.com \
    --cc=dm-devel@redhat.com \
    --cc=mpatocka@redhat.com \
    --cc=snitzer@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox