dm table: fix discard support

Remove 'discards_supported' from the dm_table structure.  The same
information can be easily discovered from the table's target(s) in
dm_table_supports_discards().

Before this fix dm_table_supports_discards() would skip checking the
individual targets' 'discards_supported' flag if any one target in the
table didn't set num_discard_requests > 0.  Now the per-target
'discards_supported' flag is effective at insuring the final DM device
advertises discard support.  But, to be clear, targets that don't
support discards (!num_discard_requests) will not receive discard
requests.

Also DMWARN if a target sets 'discards_supported' override but forgets
to set 'num_discard_requests'.

Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
This commit is contained in:
Mike Snitzer 2011-08-02 12:32:01 +01:00 committed by Alasdair G Kergon
parent 283a8328ca
commit 936688d7eb
2 changed files with 9 additions and 9 deletions

View File

@ -54,7 +54,6 @@ struct dm_table {
sector_t *highs; sector_t *highs;
struct dm_target *targets; struct dm_target *targets;
unsigned discards_supported:1;
unsigned integrity_supported:1; unsigned integrity_supported:1;
/* /*
@ -209,7 +208,6 @@ int dm_table_create(struct dm_table **result, fmode_t mode,
INIT_LIST_HEAD(&t->devices); INIT_LIST_HEAD(&t->devices);
INIT_LIST_HEAD(&t->target_callbacks); INIT_LIST_HEAD(&t->target_callbacks);
atomic_set(&t->holders, 0); atomic_set(&t->holders, 0);
t->discards_supported = 1;
if (!num_targets) if (!num_targets)
num_targets = KEYS_PER_NODE; num_targets = KEYS_PER_NODE;
@ -791,8 +789,9 @@ int dm_table_add_target(struct dm_table *t, const char *type,
t->highs[t->num_targets++] = tgt->begin + tgt->len - 1; t->highs[t->num_targets++] = tgt->begin + tgt->len - 1;
if (!tgt->num_discard_requests) if (!tgt->num_discard_requests && tgt->discards_supported)
t->discards_supported = 0; DMWARN("%s: %s: ignoring discards_supported because num_discard_requests is zero.",
dm_device_name(t->md), type);
return 0; return 0;
@ -1359,19 +1358,19 @@ bool dm_table_supports_discards(struct dm_table *t)
struct dm_target *ti; struct dm_target *ti;
unsigned i = 0; unsigned i = 0;
if (!t->discards_supported)
return 0;
/* /*
* Unless any target used by the table set discards_supported, * Unless any target used by the table set discards_supported,
* require at least one underlying device to support discards. * require at least one underlying device to support discards.
* t->devices includes internal dm devices such as mirror logs * t->devices includes internal dm devices such as mirror logs
* so we need to use iterate_devices here, which targets * so we need to use iterate_devices here, which targets
* supporting discard must provide. * supporting discard selectively must provide.
*/ */
while (i < dm_table_get_num_targets(t)) { while (i < dm_table_get_num_targets(t)) {
ti = dm_table_get_target(t, i++); ti = dm_table_get_target(t, i++);
if (!ti->num_discard_requests)
continue;
if (ti->discards_supported) if (ti->discards_supported)
return 1; return 1;

View File

@ -1179,7 +1179,8 @@ static int __clone_and_map_discard(struct clone_info *ci)
/* /*
* Even though the device advertised discard support, * Even though the device advertised discard support,
* reconfiguration might have changed that since the * that does not mean every target supports it, and
* reconfiguration might also have changed that since the
* check was performed. * check was performed.
*/ */
if (!ti->num_discard_requests) if (!ti->num_discard_requests)