* [PATCH] dm crypt: Always disable discard zeroes data flag
@ 2011-08-08 21:48 Milan Broz
2011-08-08 22:05 ` Mike Snitzer
0 siblings, 1 reply; 3+ messages in thread
From: Milan Broz @ 2011-08-08 21:48 UTC (permalink / raw)
To: dm-devel; +Cc: Milan Broz
If optional discard support in dm-crypt is enabled,
discards requests bypass crypt queue and blocks
of the underlying device are discarded.
But for read path, discarded blocks are handled
as the same as normal ciphertext blocks, thus decrypted.
So if underlying device announces discarded regions
return zeroes, dm-crypt must disable this flag because
after decryption there is just random noise instead of zeroes.
Signed-off-by: Milan Broz <mbroz@redhat.com>
---
drivers/md/dm-crypt.c | 1 +
drivers/md/dm-table.c | 19 +++++++++++++++++++
include/linux/device-mapper.h | 5 +++++
3 files changed, 25 insertions(+), 0 deletions(-)
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index 49da55c..b6ac710 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -1698,6 +1698,7 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
}
ti->num_flush_requests = 1;
+ ti->discard_zeroes_unsupported = 1;
return 0;
bad:
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index 61d3e83..5294f29 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -1330,6 +1330,22 @@ static bool dm_table_is_nonrot(struct dm_table *t)
return 1;
}
+static bool dm_table_discard_zeroes(struct dm_table *t)
+{
+ struct dm_target *ti;
+ unsigned i = 0;
+
+ /* Ensure that all targets supports discard zeroes. */
+ while (i < dm_table_get_num_targets(t)) {
+ ti = dm_table_get_target(t, i++);
+
+ if (ti->discard_zeroes_unsupported)
+ return 0;
+ }
+
+ return 1;
+}
+
void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
struct queue_limits *limits)
{
@@ -1357,6 +1373,9 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
else
queue_flag_clear_unlocked(QUEUE_FLAG_NONROT, q);
+ if (!dm_table_discard_zeroes(t))
+ q->limits.discard_zeroes_data = 0;
+
dm_table_set_integrity(t);
/*
diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h
index ba99936..2416cf1 100644
--- a/include/linux/device-mapper.h
+++ b/include/linux/device-mapper.h
@@ -208,6 +208,11 @@ struct dm_target {
* whether or not its underlying devices have support.
*/
unsigned discards_supported:1;
+
+ /*
+ * Set if this target does not return zeroes on discarded blocks.
+ */
+ unsigned discard_zeroes_unsupported:1;
};
/* Each target can link one of these into the table */
--
1.7.5.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: dm crypt: Always disable discard zeroes data flag
2011-08-08 21:48 [PATCH] dm crypt: Always disable discard zeroes data flag Milan Broz
@ 2011-08-08 22:05 ` Mike Snitzer
2011-08-09 6:44 ` Milan Broz
0 siblings, 1 reply; 3+ messages in thread
From: Mike Snitzer @ 2011-08-08 22:05 UTC (permalink / raw)
To: device-mapper development; +Cc: Milan Broz
On Mon, Aug 08 2011 at 5:48pm -0400,
Milan Broz <mbroz@redhat.com> wrote:
> If optional discard support in dm-crypt is enabled,
> discards requests bypass crypt queue and blocks
> of the underlying device are discarded.
>
> But for read path, discarded blocks are handled
> as the same as normal ciphertext blocks, thus decrypted.
>
> So if underlying device announces discarded regions
> return zeroes, dm-crypt must disable this flag because
> after decryption there is just random noise instead of zeroes.
>
> Signed-off-by: Milan Broz <mbroz@redhat.com>
> ---
> drivers/md/dm-crypt.c | 1 +
> drivers/md/dm-table.c | 19 +++++++++++++++++++
> include/linux/device-mapper.h | 5 +++++
> 3 files changed, 25 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
> index 49da55c..b6ac710 100644
> --- a/drivers/md/dm-crypt.c
> +++ b/drivers/md/dm-crypt.c
> @@ -1698,6 +1698,7 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
> }
>
> ti->num_flush_requests = 1;
> + ti->discard_zeroes_unsupported = 1;
I'd prefer 'discard_zeroes_data_unsupported'
> return 0;
>
> bad:
> diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
> index 61d3e83..5294f29 100644
> --- a/drivers/md/dm-table.c
> +++ b/drivers/md/dm-table.c
> @@ -1330,6 +1330,22 @@ static bool dm_table_is_nonrot(struct dm_table *t)
> return 1;
> }
>
> +static bool dm_table_discard_zeroes(struct dm_table *t)
Likewise, dm_table_discard_zeroes_data().
> +{
> + struct dm_target *ti;
> + unsigned i = 0;
> +
> + /* Ensure that all targets supports discard zeroes. */
> + while (i < dm_table_get_num_targets(t)) {
> + ti = dm_table_get_target(t, i++);
> +
> + if (ti->discard_zeroes_unsupported)
> + return 0;
> + }
> +
> + return 1;
> +}
> +
> void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
> struct queue_limits *limits)
> {
> @@ -1357,6 +1373,9 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
> else
> queue_flag_clear_unlocked(QUEUE_FLAG_NONROT, q);
>
> + if (!dm_table_discard_zeroes(t))
> + q->limits.discard_zeroes_data = 0;
> +
> dm_table_set_integrity(t);
>
> /*
> diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h
> index ba99936..2416cf1 100644
> --- a/include/linux/device-mapper.h
> +++ b/include/linux/device-mapper.h
> @@ -208,6 +208,11 @@ struct dm_target {
> * whether or not its underlying devices have support.
> */
> unsigned discards_supported:1;
> +
> + /*
> + * Set if this target does not return zeroes on discarded blocks.
> + */
> + unsigned discard_zeroes_unsupported:1;
> };
>
> /* Each target can link one of these into the table */
> --
> 1.7.5.4
>
> --
> dm-devel mailing list
> dm-devel@redhat.com
> https://www.redhat.com/mailman/listinfo/dm-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: dm crypt: Always disable discard zeroes data flag
2011-08-08 22:05 ` Mike Snitzer
@ 2011-08-09 6:44 ` Milan Broz
0 siblings, 0 replies; 3+ messages in thread
From: Milan Broz @ 2011-08-09 6:44 UTC (permalink / raw)
To: Mike Snitzer; +Cc: device-mapper development
On 08/09/2011 12:05 AM, Mike Snitzer wrote:
>> + ti->discard_zeroes_unsupported = 1;
>
> I'd prefer 'discard_zeroes_data_unsupported'
It was too long and I am lazy typist :-)
In fact, I know Alasdair will rename it anyway so
I do not care about the final name.
Milan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-08-09 6:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-08 21:48 [PATCH] dm crypt: Always disable discard zeroes data flag Milan Broz
2011-08-08 22:05 ` Mike Snitzer
2011-08-09 6:44 ` Milan Broz
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.